You are on page 1of 7

Assignment-1

TOE

Pratiksha R Rodewad
5th semester Aerospace Engineering
IIST,Thiruvanthapuram

March 28, 2021


Figure 1: stress tensor

#python code to compute eigen values , and eigen vectors and for checking orthogonality of eigen vector
import numpy as np
import math
from CubicEquationSolver import *
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))

print("Enter the entries in a single line (separated by space): ")

# User input of entries in a


# single line separated by space
entries = list(map(int, input().split()))

# For printing the matrix


matrix = np.array(entries).reshape(R, C)
print(’Given matrix is:’+str(matrix))
I=np.identity(3)
a = matrix[0][0]
b = matrix[0][1]
c = matrix[0][2]
d = matrix[1][0]
e = matrix[1][1]
f = matrix[1][2]
g = matrix[2][0]
h = matrix[2][1]
i = matrix[2][2]

l = matrix[0][0] + matrix[1][1] + matrix[2][2]

1
m = (e*i - f*h) + (a*i - c*g) + (a*e - b*d)
n = a*(e*i - f*h) - b*(d*i - f*g) + c*(d*h - e*g)
eigen_values = solve(1,l,m,n)
eigen_values = -1 * np.array(eigen_values)
print(’eigen values(principal stresses) are’+str(eigen_values))

#print(’for eigen value= ’+str(eigen_values[0])+’equations are: ’)


#print((str(a-eigen_values[0]))+’l1+’+(str(b))+’m1+’+(str(c))+’n1 = 0’)
#print(str(d)+’l1+’+str(e-eigen_values[0])+’m1+’+str(f)+’n1 = 0’)
#print(str(g)+’l1+’+str(h)+’m1+’+str(i-eigen_values[0])+’n1 = 0’)
#print(’ l1,m1,n1 are eigen vectors corresponding to ’+str(eigen_values[0]))

#print(’for eigen value= ’+str(eigen_values[1])+’equations are: ’)


#print((str(a-eigen_values[1]))+’l2+’+(str(b))+’m2+’+(str(c))+’n2 = 0’)
#print(str(d)+’l2+’+str(e-eigen_values[1])+’m2+’+str(f)+’n2 = 0’)
#print(str(g)+’l2+’+str(h)+’m2+’+str(i-eigen_values[1])+’n2 = 0’)
#print(’ l2,m2,n2 are eigen vectors corresponding to ’+str(eigen_values[1]))

#print(’for eigen value= ’+str(eigen_values[2])+’equations are: ’)


#print((str(a-eigen_values[2]))+’l3+’+(str(b))+’m3+’+(str(c))+’n3 = 0’)
#print(str(d)+’l3+’+str(e-eigen_values[2])+’m3+’+str(f)+’n3 = 0’)
#print(str(g)+’l3+’+str(h)+’m3+’+str(i-eigen_values[2])+’n3= 0’)
#print(’ l3,m3,n3 are eigen vectors corresponding to ’+str(eigen_values[2]))

#print(’ To find l,m,n(for each eigen value),we need to find p,q,r ’)


#print(’where,l=p/(p^2+q^2+r^2)^0.5,m=q/(p^2+q^2+r^2)^0.5,n=r/(p^2+q^2+r^2)^0.5’)
#print(’let us consider p=1 and p^2+q^2+r^2=1’)

#print(’for eigen value=’+str(eigen_values[0])+’equation in p,q,r terms are’)


#print(str(h)+’q+(’+str(c)+’)r =(’+str(eigen_values[0]-a))
#print((str(e-eigen_values[0])+’q+(’+str(d)+’)r =(’+ str(d)))
#print(str(h)+’q+(’+str(i-(eigen_values[0]))+’r =(-’+str(g))
A=np.array([[h,c],[e-eigen_values[0],d]])
B=np.linalg.inv(A)
C=np.array([[eigen_values[0]-a],[-d]])
z=np.dot(B,C)
#print(’from the above euation we get q and r which are:’)
#print(np.dot(B,C))
s=1+z[0]*z[0]+z[1]*z[1]
#print(’values of p^2+q^2+r^2 is’)
#print(s)
l1=1/math.sqrt(s)
m1=z[0]/math.sqrt(s)
n1=z[1]/math.sqrt(s)
print(’l1,m1,n1 are eigen vector(v1) corresponding to ’+str(eigen_values[0])+’are’)
print(np.array([[l1],m1,n1]))

2
#print(’for eigen value=’+str(eigen_values[1])+’equation in p,q,r terms are’)
#print(str(h)+’q+(’+str(c)+’)r =(’+str(eigen_values[1]-a))
#print((str(e-eigen_values[1])+’q+(’+str(d)+’)r =(’+ str(d)))
#print(str(h)+’q+(’+str(i-(eigen_values[1]))+’r =(-’+str(g))
A=np.array([[h,c],[e-eigen_values[1],d]])
B=np.linalg.inv(A)
C=np.array([[eigen_values[1]-a],[-d]])
k=np.dot(B,C)
#print(’from the above euation we get q and r which are:’)
#print(np.dot(B,C))
o=1+k[0]*k[0]+k[1]*k[1]
#print(’values of p^2+q^2+r^2 is’)
#print(o)
l2=1/math.sqrt(o)
m2=k[0]/math.sqrt(o)
n2=k[1]/math.sqrt(o)
print(’l2,m2,n2 are eigen vector(v2) corresponding to ’+str(eigen_values[1])+’are’)
print(np.array([[l2],m2,n2]))

#print(’for eigen value=’+str(eigen_values[2])+’equation in p,q,r terms are’)


#print(’for eigen value=’+str(eigen_values[2])+’equation in p,q,r terms are’)
#print(str(h)+’q+(’+str(c)+’)r =(’+str(eigen_values[2]-a))
#print((str(e-eigen_values[2])+’q+(’+str(d)+’)r =(’+ str(d)))
#print(str(h)+’q+(’+str(i-(eigen_values[2]))+’r =(-’+str(g))
A=np.array([[h,c],[e-eigen_values[2],d]])
B=np.linalg.inv(A)
C=np.array([[eigen_values[2]-a],[-d]])
u=np.dot(B,C)
#print(’from the above equation we get q and r which are:’)
#print(np.dot(B,C))
t=1+u[0]*u[0]+u[1]*u[1]
#print(’values of p^2+q^2+r^2 is’)
#print(t)
l3=1/math.sqrt(t)
m3=u[0]/math.sqrt(t)
n3=u[1]/math.sqrt(t)
print(’l3,m3,n3 are eigen vector(v3) corresponding to ’+str(eigen_values[2])+’are’)
print(np.array([[l3],m3,n3]))
print(’to check orthogonality:v1.v2=v2.v3=v1.v3=0’)
s1=l1*l2+m1*m2+n1*n2
s2=l2*l3+m2*m3+n2*n3
s3=l1*l3+m1*m3+n1*n3
print(’v1.v2 is:’)
print(s1)
print(’v2,v3 is:’)
print(s2)
print(’v1.v3’)
print(s3)

3
SAMPLE EXAMPLE
consider a A matrix=  
2 −1 0
−1 2 −1
0 −1 2

Figure 2: output of given matrix

4
result
stress tensor is matrix with all stress elements.
we consider the matrix A of 3 by 3 order and computed the eigen values , eigen vectors and checked the
orthogonality of eigen vectors.
figure.2 shows output of given matrix A

5
Bibliography

[1] https : //stackabuse.com/solving − systems − of − linear − equations − with − pythons − numpy/

[2] https : //github.com/shril/CubicEquationSolver


[3] https : //www.mathsisf un.com/algebra/matrix − inverse.html

You might also like