Questions and discussion for this lecture live here. Fire away by hitting Reply below
hello sir,
when I am running the code below, I am getting an error, I mentioned the code and error below:
Code:
nDOF = np.amax(members) * 3
Kp = np.zeros([nDOF, nDOF])
for n, mbr in enumerate(members):
[K11, K12, K21, K22] = calculateKg(n+1)
node_i = mbr[0]
node_j = mbr[1]
# Primary stiffness matrix associated with each node
# node-1 gives indices 0,1,2 and node-2 gives indices 3,4,5
ia = 3*node_i - 3
ib = 3*node_i - 1
ja = 3*node_j - 3
jb = 3*node_j - 1
Kp[ia:ib + 1, ia:ib + 1 ] = Kp[ia:ib + 1, ia:ib + 1 ] + K11
Kp[ia:ib + 1, ja:jb + 1 ] = Kp[ia:ib + 1, ja:jb + 1 ] + K12
Kp[ja:jb + 1, ia:ib + 1 ] = Kp[ja:jb + 1, ia:ib + 1 ] + K21
Kp[ja:jb + 1, ja:jb + 1 ] = Kp[ja:jb + 1, ja:jb + 1 ] + K22
**Error:**
IndexError Traceback (most recent call last)
Cell In [7], line 5
2 Kp = np.zeros([nDOF, nDOF])
3 for n, mbr in enumerate(members):
----> 5 [K11, K12, K21, K22] = calculateKg(n+1)
6 node_i = mbr[0]
7 node_j = mbr[1]
Cell In [6], line 2, in calculateKg(memberNo)
1 def calculateKg(memberNo):
----> 2 theta = orientations[memberNo - 1]
3 L = lengths[memberNo - 1]
4 c = math.cos(theta)
IndexError: index 0 is out of bounds for axis 0 with size 0
please provide the solution why this error is coming, because I am following the same code as you.
Hey @jyskrwr - it’s difficult for me to diagnose the source of the problem with an isolated code block like this. But it will be a simple error to fix - it looks like you’re trying to access an array element when the array has not been correctly initialised - it has nothing in it basically.
The most direct route to a solution is for you to download the code for this section that comes with the course and compare your code with the course code - doing this you will quickly be able to identify the source of the issue by adding print statements as you debug to track down where exactly your code output deviates from the course code output.
Unfortunately debugging like this is also part of the learning process
Seán