21. Matrix representation and the eigenproblem

Questions and discussion for this lecture live here. Fire away by hitting Reply below :fire:

Greetings,
I used the same code of your program and run it. I got this message at the last stage of plot:

#Plotting
fig, axes = plt.subplots(figsize=(15,8),nrows=1,ncols=3)

modeCoords1 = np.array([0, eVecA1[0], eVecA1[1], eVecA1[2]], float)
axes[0].plot([0,0,0,0],[0, h1, h1+h2, h1+h2+h3],‘-k’)
axes[0].plot(modeCoords1,[0, h1, h1+h2, h1+h2+h3],‘-’)
axes[0].plot(modeCoords1[1],[h1],‘-o’,markerfacecolor=‘red’, markeredgecolor=‘k’, markersize=13)
axes[0].plot(modeCoords1[2],[h1+h2],‘-o’,markerfacecolor=‘red’, markeredgecolor=‘k’, markersize=13)
axes[0].plot(modeCoords1[3],[h1+h2+h3],‘-o’,markerfacecolor=‘red’, markeredgecolor=‘k’, markersize=13)
axes[0].set_xlabel(‘Relative amplitude’)
axes[0].set_ylabel(‘Height (m)’)
axes[0].set_title(‘Mode shape for $\omega_1$ = {one} rads/sec’.format(one=round(OmegaA,1)))
axes[0].set_xlim([-2.5, 2.5])
axes[0].grid()

The error was:
ValueError Traceback (most recent call last)
Cell In[41], line 4
1 #Plotting
2 fig, axes = plt.subplots(figsize=(15,8),nrows=1,ncols=3)
----> 4 modeCoords1 = np.array([0, eVecA1[0], eVecA1[1], eVecA1[2]], float)
5 axes[0].plot([0,0,0,0],[0, h1, h1+h2, h1+h2+h3],‘-k’)
6 axes[0].plot(modeCoords1,[0, h1, h1+h2, h1+h2+h3],‘-’)

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (4,) + inhomogeneous part.

Please let me know what is the issue:

Hey @joejavady, the issues arises because eVecA1[0], eVecA1[1], and eVecA1[2] all actually evaluate to a numpy array, we see this if we evaluate,

print(type(eVecA1[0]))

…we get <class 'numpy.ndarray'>. At the original time of writing, this was acceptible syntax - but not any longer. So, we need to specify or index into the value inside the array, as follows:

eVecA1[0][0]

…which will yield 1.0 rather than [1.0].

So you would alter line four as follows:

modeCoords1 = np.array([0, eVecA1[0][0], eVecA1[1][0], eVecA1[2][0]], float)

Make sure to do the same for lines 16 and 28. This will resolve the issue.

(Note that the code and notebook for this lecture have been updated to reflect the correction outlined above.)

ok, thank you. it woks now

1 Like