```python
from sympy.interactive import printing
printing.init_printing(use_latex = True)
import numpy as np
import scipy as sc
import sympy as sp
import matplotlib as mp
import matplotlib.pyplot as plt
from numpy.linalg import norm
from mpl_toolkits.mplot3d import axes3d
```

$PROBLEM$ $1$


```python
A=np.array([2,-3,7])
B=np.array([-4,1,0])
C=np.array([5,-1,9])
D=np.array([0,0,2])
```


```python
print("Part A")
```

    Part A



```python
print(np.dot(A,B), "is the dot product of A and B")
print(np.dot(C,D), "is the dot product of C and D")

```

    -11 is the dot product of A and B
    18 is the dot product of C and D



```python
print("\n\n\n\nPart B ")
```

    
    
    
    
    Part B 



```python
R=np.cross(A,B)
print(R, "is the resultant vector of A cross B")
print(norm(R),"is the magnitude of A cross B")
i=np.array([-7/norm(R),0,0])
j=np.array([0,-28/norm(R),0])
k=np.array([0,0,-10/norm(R)])
x=np.arccos(np.dot(R,i)/(norm(R)*norm(i)))
y=np.arccos(np.dot(R,j)/(norm(R)*norm(j)))
z=np.arccos(np.dot(R,k)/(norm(R)*norm(k)))
print(x,y,z)
# print(np.degrees(x),"degrees angle with x-axis")
# print(np.degrees(y),"degress angle with y-axis")
# print(np.degrees(z),"degrees angle with z-axis")
```

    [ -7 -28 -10] is the resultant vector of A cross B
    30.54504869860253 is the magnitude of A cross B
    1.339571719189226 0.41110738580715916 1.2372612783481713



```python
print("\n\n\nPart C\n")
V=np.cross(B,D)
U=np.array([2/norm(V),8/norm(V),0/norm(V)])
print(U, "is the Unit Vector along BxD")
```

    
    
    
    Part C
    
    [0.24253563 0.9701425  0.        ] is the Unit Vector along BxD



```python
print("\n\n\n\nPart D\n")
```

    
    
    
    
    Part D
    



```python
a=print(norm(A))
d=print(norm(B))
c=print(norm(C))
d=print(norm(D))
print ("The vector with the largest magnitude is C \n")
```

    7.874007874011811
    4.123105625617661
    10.344080432788601
    2.0
    The vector with the largest magnitude is C 
    



```python
print("\n\n\n\nQUESTION 2 \n")
```

    
    
    
    
    QUESTION 2 
    



```python
print("\n\n\n\nPart A\n")
```

    
    
    
    
    Part A
    



```python
a=np.array([[1,0,2],[2,1,3],[1,3,1],[4,1,0,]])
b=np.array([[2,0,1,2],[1,2,1,3],[5,3,1,4]])
print(a,"\n")
print(b,"\n")
print(a@b)
```

    [[1 0 2]
     [2 1 3]
     [1 3 1]
     [4 1 0]] 
    
    [[2 0 1 2]
     [1 2 1 3]
     [5 3 1 4]] 
    
    [[12  6  3 10]
     [20 11  6 19]
     [10  9  5 15]
     [ 9  2  5 11]]



```python
print("\n\n\n\nPart B\n")
print("Yes it possible to do the multiplication of a.aT because a transpose is just change of rows and columns wich is vali to results.\n")
print("Here is the result of aaT\n")
V=a@a.T
print(V)
```

    
    
    
    
    Part B
    
    Yes it possible to do the multiplication of a.aT because a transpose is just change of rows and columns wich is vali to results.
    
    Here is the result of aaT
    
    [[ 5  8  3  4]
     [ 8 14  8  9]
     [ 3  8 11  7]
     [ 4  9  7 17]]



```python
print("\n\n\n\nPart C\n")
U=(a@b).T
W=(b.T)@(a.T)
print(U,"\n")
print(W,"\n\n Thus we can see that (ab)T=bT@aT are equal")

```

    
    
    
    
    Part C
    
    [[12 20 10  9]
     [ 6 11  9  2]
     [ 3  6  5  5]
     [10 19 15 11]] 
    
    [[12 20 10  9]
     [ 6 11  9  2]
     [ 3  6  5  5]
     [10 19 15 11]] 
    
     Thus we can see that (ab)T=bT@aT are equal



```python
print("\n\n\n\nPart D\n")
c=np.array([[1,0,2],[2,1,3],[1,3,4]])
d=np.array([[2,0,1],[1,2,1],[5,0,1]])
V=np.linalg.inv(c@d)
W=np.linalg.inv(d)@np.linalg.inv(c)
print(W,"\n")
print(V)

```

    
    
    
    
    Part D
    
    [[ 0.66666667 -0.6         0.2       ]
     [ 0.33333333 -0.7         0.4       ]
     [-2.33333333  2.4        -0.8       ]] 
    
    [[ 0.66666667 -0.6         0.2       ]
     [ 0.33333333 -0.7         0.4       ]
     [-2.33333333  2.4        -0.8       ]]



```python
print("\n\n\n\npart E\n")
print(np.linalg.inv(c).T)
print("\n")
print(np.linalg.inv(c.T))

```

    
    
    
    
    part E
    
    [[-1.  -1.   1. ]
     [ 1.2  0.4 -0.6]
     [-0.4  0.2  0.2]]
    
    
    [[-1.  -1.   1. ]
     [ 1.2  0.4 -0.6]
     [-0.4  0.2  0.2]]



```python
print("\n\n\n\n\nQUESTION 3 \n")
print("2x1 + 0.7x2 - 3.5x3 + 7x4 - 0.5x5 = 2 \n")
print("-1.2x1 + 2.7x2 + 0x3 - 3x4 - 2.5x5 = -17 \n")
print("x1 + x2 - x3 - x4 + x5 = 5 \n")
print("2.9x1 + 0x2 + 0x3 + 0x4 + 7.5x5 = 0 \n")
print("0x1 + 0x2 + 0x3 - 2.7x4 - 5.5x5 = -11 \n")
```

    
    
    
    
    
    QUESTION 3 
    
    2x1 + 0.7x2 - 3.5x3 + 7x4 - 0.5x5 = 2 
    
    -1.2x1 + 2.7x2 + 0x3 - 3x4 - 2.5x5 = -17 
    
    x1 + x2 - x3 - x4 + x5 = 5 
    
    2.9x1 + 0x2 + 0x3 + 0x4 + 7.5x5 = 0 
    
    0x1 + 0x2 + 0x3 - 2.7x4 - 5.5x5 = -11 
    



```python
E=np.array([[2,0.7,-3.5,7,-0.5],[-1.2,2.7,0,-3,-2.5],[1,1,-1,-1,1],[2.9,0,0,0,7.5],[0,0,1.8,-2.7,-5.5]])
G=np.array([[2,-17,5,0,-11]]).T
H=np.linalg.inv(E)@G
print(E,"\n")
print(G,"\n")
print(H,"\n")
print("Values are x1=-0.56, x2-11.34, x3=-12.19, x4=-4.49, x5=0.21")

```

    [[ 2.   0.7 -3.5  7.  -0.5]
     [-1.2  2.7  0.  -3.  -2.5]
     [ 1.   1.  -1.  -1.   1. ]
     [ 2.9  0.   0.   0.   7.5]
     [ 0.   0.   1.8 -2.7 -5.5]] 
    
    [[  2]
     [-17]
     [  5]
     [  0]
     [-11]] 
    
    [[ -0.56501824]
     [-11.34361865]
     [-12.19151891]
     [ -4.49864426]
     [  0.21847372]] 
    
    Values are x1=-0.56, x2-11.34, x3=-12.19, x4=-4.49, x5=0.21



```python
print ("Check Calculation of RHS with the LHS\n")
print(2*-0.565 + 0.7*-11.34 - 3.5*-12.19 + 7*-4.49 - 0.5*0.21, " == 2 \n")
print(-1.2*-0.565 + 2.7*-11.34 - 0*-12.19 + -3*-4.49 - 2.5*0.21, " == -17 \n")
print(1*-0.565 + 1*-11.34 - 1*-12.19 - 1*-4.49 + 1*0.21, " == 5 \n")
print(2.9*-0.565 + 7.5*0.21, " == 0 \n")
print(1.8*-12.19 + -2.7*-4.49 - 5.5*0.21, " == -11 \n")
```

    Check Calculation of RHS with the LHS
    
    2.0620000000000016  == 2 
    
    -16.994999999999997  == -17 
    
    4.985  == 5 
    
    -0.06349999999999989  == 0 
    
    -10.973999999999998  == -11 
    


d2f8f3a4fa6d61e6f19abc26c247e8cbe9ff144b
ipynb
Jupyter Notebook
assignments/assignment01/assignment01_solution.ipynb
eyobghiday/computational-mechanics
c64aebca5d26fdf5fc93977a5ec3dbaa4e715a48
MIT
2021-06-27T06:21:23.000Z
2022-03-17T09:48:45.000Z
assignments/assignment01/assignment01_solution.ipynb
eyobghiday/computational-mechanics
c64aebca5d26fdf5fc93977a5ec3dbaa4e715a48
MIT
assignments/assignment01/assignment01_solution.ipynb
eyobghiday/computational-mechanics
c64aebca5d26fdf5fc93977a5ec3dbaa4e715a48
MIT
Qwen/Qwen-72B
1. YES
2. YES