I have a problem with sympy where it won't update my values. So I'm trying to do an iterative method for solving $\sigma_x$ and when I try to put numerical values into my expression it won't update.
I have imported sympy as sy
So I first have this code:
q,b,E,t,nu,L,z,x,y = sy.symbols("q,b,E,t,nu,L,z,x,y")
D = (E*t**3)/(12*(1-nu**2))
q_0 = 4*q/(sy.pi*b) * sy.sin(sy.pi/2)*(1-sy.cos(sy.pi))
D2 = (sy.pi**2 / L**2) + (sy.pi**2 / b**2)
w = q_0/(D* D2**2) * sy.sin(sy.pi*x/L) * sy.sin(sy.pi * y / b)
M = 4
N = 4
w_iterert = 0
for m in range(1,M+1):
for n in range(N+1):
q_iterert = 4*q/(sy.pi*b*m)*sy.sin(sy.pi*n/2)*(1-sy.cos(sy.pi*m))
w_mn = q_iterert/(D*((sy.pi**2*m**2 / L**2) + (sy.pi**2 * n**2 / b**2))**2)
w_iterert += w_mn*sy.sin(m*pi*x/L)*sy.sin(n*pi*y/b)
Then I plot the analytical expression:
w_iterert
And now I use formulas to find my sigma_x:
w_xx_iter = sy.diff(w_iterert,x,2)
w_yy_iter = sy.diff(w_iterert,y,2)
sigma_x_iter = - z*E/(1-nu**2)*(w_xx_iter+nu*w_yy_iter)
Here is where I get it wrong. now I do this:
E = 210000
pi = sy.pi
q = 20
nu = 0.3
L = 4000
b = 1000
t = 10
x = 2
z = t/2
y = b/2
sigma_x_iter
And I would expect this to update the values and give me the numerical value. Instead I just get the same analytical expression. How can I update my values?
I tried everything, I just wrote and tried to copy the text into another notebook which obviously worked. But then I can't change the M N values and get a different result unless I do it automatically.
sympy
tutorial more. Specifically docs.sympy.org/latest/tutorial/gotchas.html#symbols. You created symbols and assigned them to Python variables. Reassigning those variables looses the connection between the variables and symbols. You have to usesubs
to assign values to the symbols. – Kingbolt