You are on page 1of 1

2_Newton Raphson Method.

py

1 import numpy as np
2 ks= np.matrix([[300,-250],[-250,400]]).astype(float)
3 kt= np.matrix([[300,-250],[-250,400]]).astype(float)
4 force=np.matrix([[400],[120]])
5  
6 error=np.matrix(force)
7 # derror=np.matrix([[0],[0],[0]])
8 u=np.matrix([[0],[0]])
9 i=1
10 while True:
11 print(f"Iteration={i}")
12 i=i+1
13
14 derror=np.linalg.inv(kt).dot(error)
15 print("Change in displacement\n")
16 print(derror)
17 u=u+derror
18 print("Displacement\n")
19 print(u)
20 ks[0,0]=300-20*u[0]+25*u[1]
21 ks[0,1]=-250+25*u[0]-25*u[1]
22 ks[1,1]=450-25*u[0]+10*u[1]
23 ks[1,0]=ks[0,1]
24 print("Secant stiffness\n")
25 print(ks)
26 error=force-ks.dot(u)
27 print("Force error\n")
28 print (error)
29 kt[0,0]=300-40*u[0]+50*u[1]
30 kt[0,1]=-250+50*u[0]-50*u[1]
31 kt[1,1]=450-50*u[0]+20*u[1]
32 kt[1,0]=kt[0,1]
33 print("Tangential stiffness\n")
34 print(kt)
35 if(abs(derror[0])<0.0001 and abs(derror[1])<0.0001):
36 break
37  

You might also like