0% found this document useful (0 votes)
29 views1 page

Mse Practical

A

Uploaded by

agrawalaman2093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Mse Practical

A

Uploaded by

agrawalaman2093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

MSE 1940805

Ques 1

a.

In [6]: import numpy as np

a = np.array([4,3,2]) # vector u
b = np.array([8,5,6]) # vector v:

#Projection vector a on vector b

b_norm = np.sqrt(sum(b**2))

# find dot product using np.dot()


proj_a_b = (np.dot(a, b)/b_norm**2)*b

print("Projection of Vector a on b is: ", proj_a_b)

#Projection vector b on vector a

a_norm = np.sqrt(sum(a**2))

# find dot product using np.dot()


proj_b_a = (np.dot(b, a)/a_norm**2)*a

print("Projection of Vector b on a is: ", proj_b_a)

Projection of Vector a on b is: [3.776 2.36 2.832]


Projection of Vector b on a is: [8.13793103 6.10344828 4.06896552]

B.

In [21]: import matplotlib.pyplot as plt


from sympy import *
from mpl_toolkits import mplot3d

ax = plt.axes(projection='3d')
t = np.linspace(0,5,1000)
X = (4+np.sin(20*t))*np.cos(t)
Y = (4+np.sin(20*t))*np.sin(t)
Z = np.cos(20*t)
ax.plot3D(x, y, z, 'green')

t=Symbol('t')
vec=[X, Y, Z]
diffvec=[]
for el in vec:
diffvec.append(diff(el,t))
tmp = 0
for elem in diffvec:
tmp = simplify(tmp + elem**2)
tmp
arc_length=Integral(tmp**(1/2), (t,1,2)).doit()
print("The arc length is", arc_length)
arc_length

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-f1e683e42944> in <module>
18 tmp = 0
19 for elem in diffvec:
---> 20 tmp = simplify(tmp + elem**2)
21 tmp
22 arc_length=Integral(tmp**(1/2), (t,1,2)).doit()

TypeError: unsupported operand type(s) for ** or pow(): 'ImmutableDenseNDimArray' and 'int'

QUES 2

A. i

In [24]: x, y= np.meshgrid(range(10),range(10))
z=np.tan(x)

#plot the surface

ax= plt.figure().gca(projection='3d')
ax.plot_surface(x,y,z)
plt.title("Plane")

ax.set_xlabel('$X$')
ax.set_ylabel('$Y$')
ax.set_zlabel('$Z$')
plt.show()

A. ii.

In [9]: from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline
x=np.arange(-10,10,0.1)
y=np.arange(-10,10,0.1)
X,Y=np.meshgrid(x,y)
Z=9*(((X)**2)/9 + ((Y)**2)/16 - 1)*(1/2)
fig=plt.figure(figsize=(6,6))
ax=fig.add_subplot(111,projection='3d')
ax.plot_surface(X,Y,Z)
plt.show()

A. iii.

In [25]: x, y= np.meshgrid(range(10),range(10))
z=(8*x**2-y)
#plot the surface
ax= plt.figure().gca(projection='3d')
ax.plot_surface(x,y,z)
plt.title("Plane")
ax.set_xlabel('$X$')
ax.set_ylabel('$Y$')
ax.set_zlabel('$Z$')
plt.show();

B.
In [26]: init_printing()
t=Symbol('t')
r=Matrix([t+1, t**2+1, 2*t])
v=simplify(diff(r,t))
speed=sqrt(sum(matrix_multiply_elementwise(v, v)))
A=simplify(diff(v,t))
print("Position vector, r(t)=",r[0]," i + ",r[1]," j + ", r[2], " k")
print("Velocity vector, v(t)=",v[0]," i + ",v[1]," j + ", v[2], " k")
print("Speed, |v(t)|=",speed)
print("Acceleration, a(t)=",A[0]," i + ",A[1]," j + ", A[2], " k")
r_p=r.subs(t, 7*pi/4)
v_p=v.subs(t, 7*pi/4)
speed_p=speed.subs(t, 7*pi/4)
tan_p=simplify(r_p+(v_p/speed_p))
ax = plt.axes(projection='3d')
t = np.linspace(0, 10, 1000)
X = t+1
Y = t**2+1
Z = 2*t
X_tan=np.array([float(r_p[0]), float(tan_p[0])])
Y_tan=np.array([float(r_p[1]), float(tan_p[1])])
Z_tan=np.array([float(r_p[2]), float(tan_p[2])])
ax.plot3D(X, Y, Z)
ax.plot3D(X_tan, Y_tan, Z_tan)

Position vector, r(t)= t + 1 i + t**2 + 1 j + 2*t k


Velocity vector, v(t)= 1 i + 2*t j + 2 k
Speed, |v(t)|= sqrt(4*t**2 + 5)
Acceleration, a(t)= 0 i + 2 j + 0 k

Out[26]: [<mpl_toolkits.mplot3d.art3d.Line3D at 0x7fd2398a8190>]

In [ ]:

You might also like