27. Element stiffness matrices

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

I’m not sure this is the correct place for questions, but I sure hope so. I opened the corresponding Jupyter Truss file for Lecture 27, opened it and was following along fine, when I tried running print(K11_12), and got this error message:


NameError Traceback (most recent call last)
/var/folders/zh/gkh9j0mx7fb2qd1mlpbv5njm0000gn/T/ipykernel_13499/3205956986.py in
3
4 #Top left quadrant of global stiffness matrix element 1
----> 5 e11 = math.cos(theta)**2
6 e12 = math.cos(theta)*math.sin(theta)
7 e21 = math.cos(theta)*math.sin(theta)

NameError: name ‘math’ is not defined

I am unsure how to resolve this issue. I have not otherwise edited or altered the original file in any way.
Regards,
Tony

Actually I imported the math module again in this section under the “Element A” header and it worked. Otherwise it does not. I am using a Mac.

Hi Tony,

Yes this is indeed the right place to post questions.

The error indicates that the math library was not imported when you executed the code to define e11. This should be imported with the other dependencies in the first code block immediately below the image of the truss…

#DEPENDENCIES
import math #Math functionality
import numpy as np #Numpy for working with arrays
import matplotlib.pyplot as plt #Plotting functionality 

#Constants
E = 200*10**9 #(N/m^2)
A = 0.005 #(m^2)
nDoF = 6 #Total number of degrees of freedom in the problem
restrainedDoF = [1,2,5,6] #The degrees of freedom restrained by supports

Let me know if you have any further issues.

Seán

Interestingly, I also found that I need not have imported the math module again, but that simply running (shift-enter) that initial block of imports did the trick. I had previously not done so, and this may have contributed to the ‘not defined’ error, as not having ran it may have been equated to it not existing at all. Regardless, thank you for the prompt reply and assistance.

Regards,
Tony

Great Tony!
:+1:
Seán