You are on page 1of 18

Presentation5

PYTHON TO C

P.Srijith Reddy
EE19BTECH11041
IIT Hyderabad

September 17, 2019

1 / 17
Outline

1 Problem

2 Solution
Finding angle between A and B.

3 solution
proof for expansion of A×(B × C )

4 code in python

5 Plot

2 / 17
Problem

Problem Statement

Let A,B,C be three unit vectors such that



3
A × (B × C) = (B + C) (2.1)
2
If B is not parallel to C,then find the angle between A and B.

3 / 17
Solution Finding angle between A and B.

Finding angle between A and B

Given that A,B,C are unit vectors and



3
A × (B × C) = (B + C) (3.1)
2
We know that
A × (B × C) = (AT C)B − (AT B)C (3.2)

4 / 17
solution proof for expansion of A×(B × C )

PROOF
Let  
ax  
A = ay  i j k (4.1)
az
 
bx  
B = by  i j k
 (4.2)
bz
 
cx  
C = cy  i j k (4.3)
cz
Now  
i j k
B × C = bx
 by bz  (4.4)
cx cy cz

B × C = (by cz − bz cy )i − (bx cz − bz cx )j + (bx cy − by cx )k (4.5)


5 / 17
solution proof for expansion of A×(B × C )

Now
 
i j k
A × (B × C) =  ax ay az  (4.6)
by cz − bz cy −(bx cz − bz cx ) bx cy − by cx

Now expanding A×(B × C) and considering x component only


=⇒ i : ay (bx cy − by cx ) + az (bx cz − bz cx )
=(ay cy + az cz )bx − (ay by + az bz )cx
=(ay cy + az cz )bx − (ay by + az bz )cx + ((ax cx )bx − (ax bx )cx ))
=(ax cx + ay cy + az cz )bx − (ax bx + ay by + az cz )cx
=i((AT C )bx − (AT B)cx )
Similarly we can show for j and k components.
Hence
A × (B × C) = (AT C)B − (AT B)C (4.7)

6 / 17
solution proof for expansion of A×(B × C )

Now using equation (3.1) and equation(3.2)



3
(AT C)B − (AT B)C = (B + C) (4.8)
2
Rearranging the terms we get the following equation
√ √
T 3 T 3
(A C − )B = (A B + )C (4.9)
2 2
Applying cross product on both sides with B we get
√ √
T 3 T 3
(A C − )B × B = (A B + )C × B (4.10)
2 2
Since
B×B=0 (4.11)

7 / 17
solution proof for expansion of A×(B × C )

therefore √
T 3
(A B + )C × B = 0 (4.12)
2
Either √
T 3
(A B + )=0 (4.13)
2
or
C×B=0 (4.14)
But since it is given that B is not parallel to C,

C × B 6= 0 (4.15)

So, √
T 3
(A B + )=0 (4.16)
2
implies √
T 3
A B=− (4.17)
2
8 / 17
solution proof for expansion of A×(B × C )

AT B = kAkkBkCOS(θ1 ) (4.18)
where θ1 is angle between A and B. Since,

kAk = kBk = 1 (4.19)



3
cos(θ1 ) = − (4.20)
2

θ1 = (4.21)
6

9 / 17
solution proof for expansion of A×(B × C )

Similarly, we get equation(3.17)by substituting equation(3.8) in


equation(3.4). √
T 3
A C= (4.22)
2

AT C = kAkkCkCOS(θ2 ) (4.23)
where θ2 is angle between A and C. Since,

kAk = kCk = 1 (4.24)



3
cos(θ2 ) = (4.25)
2
π
θ2 = (4.26)
6

10 / 17
code in python

code in python

from mpl toolkits.mplot3d import Axes3D


import matplotlib.pyplot as plt
from funcs import ∗
import numpy as np
import math
m = −(np.sqrt(3))/2#=A.T@B
a=1#=np.linalg.norm(A)
b=1#=np.linalg.norm(B)
k=m/(a∗b)
theta=math.acos(k)∗180/np.pi
print (theta)
#defining lines : x(k) = A + k∗l
O = np.array([0,0,0]).reshape((3,1))
l1 = np.genfromtxt(”A.dat”).reshape((3,1))
O = np.array([0,0,0]).reshape((3,1))
l2 = np.genfromtxt(”C.dat”).reshape((3,1))

11 / 17
code in python

code in python

#creating x,y for 3D plotting


len = 10
xx, yy = np.meshgrid(range(len), range(len))
#setting up plot
fig = plt.figure()
ax = fig.add subplot(111,projection=’3d’)
O = np.array([0,0,0]).reshape((3,1))
l3= np.genfromtxt(”B.dat”).reshape((3,1))
A = np.genfromtxt(”A.dat”).reshape((3,1))
B = np.genfromtxt(”B.dat”).reshape((3,1))
C = np.genfromtxt(”C.dat”).reshape((3,1))
l1 p = line dir pt(l1,O)
l2 p = line dir pt(l2,O)
l3 p = line dir pt(l3,O)
z=xx∗0

12 / 17
code in python

code in python

ax.scatter(O[0],O[1],O[2],’o’,label=”Point O”)
ax.scatter(A[0],A[1],A[2],’o’,label=”Point A”)
ax.scatter(C[0],C[1],C[2],’o’,label=”Point C”)
ax.scatter(B[0],B[1],B[2],’o’,label=”Point B”)
#ax.plot surface(xx, yy, z, color=’r’,alpha=1)

#plotting line
plt.plot(l1 p[0,:],l1 p[1,:],l1 p[2,:],label=”Line L1”)
plt.plot(l2 p[0,:],l2 p[1,:],l2 p[2,:],label=”Line L2”)
plt.plot(l3 p[0,:],l3 p[1,:],l3 p[2,:],label=”Line L3”)

#corresponding z for planes


#plotting planes

#show plot
plt.xlabel(’$x$’);plt.ylabel(’$y$’)
plt.legend(loc=’best’);plt.grid()
plt.show()

13 / 17
code in python

code in c used for uploading

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include ”coeffs.h”
int main() //main function begins
{
double∗∗B=createMat(3,1);
B[0][0]=−sqrt(3)/2;B[1][0]=0.5;B[2][0]=0;
printf(”B=\n”);savetxt(B,”B.dat”,3,1);
print(B,3,1);
double∗∗C=createMat(3,1);
C[0][0]=sqrt(3)/2;C[1][0]=0.5;C[2][0]=0;
printf(”C=\n”);savetxt(C,”C.dat”,3,1);

14 / 17
code in python

code in c used for uploading

print(C,3,1);//Let P be parallel to A ,so P=C+qB, q comes out to be −1


double ∗∗P=linalg sub(C, B, 3, 1);
printf(”P=\n”);
print(P,3,1);
double m=linalg norm(P, 3);
double s=1/m;
double ∗∗A=linalg scalmatmul(P, s,3, 1);
printf(”A=\n”);
print(A,3,1);savetxt(A,”A.dat”,3,1);
return 0;
}

15 / 17
code in python

Now we are going to plot one set of vectors satisfying given condition and
 
1
A = 0 (5.1)
0
 √ 
− 3/2
B =  1/2  (5.2)
0
√ 
3/2
C =  1/2  (5.3)
0
satisfy the given condition.

16 / 17
Plot

Plot
The code in
https://github.com/SRIJITH01/Srijith/blob/master/presentation2.py

plots Fig. 1.

Figure: The above plot is for set of vectors staisfying given condition .
17 / 17

You might also like