Maths Ans
Maths Ans
Output
Q2:- Generate a 2D plot for the following functions using the Python. i. 𝑦 = −𝑥 sin , −5𝜋 ≤ 𝑥 ≤ 5𝜋 ii. 𝑦 = 1 1+𝑥 2 log
, −5 ≤ 𝑥 ≤ 5
Program:- I)
import numpy as np
x=np.linspace(-5*pi,5*pi)
y=x*sin(x)
plot(x,y)
show()
Output:-
II)Program:-
import numpy as np
x=np.linspace(-5,5)
y=(1/(1+x**2))*log(x)
plot(x,y)
show()
Output:-
3.Plot the graph of 𝑦 = 𝑒 −𝑥 2 in [−5,5] with green dashed-points line with Upward- Pointing triangleProgram:-
import numpy as np
x=np.linspace(-5,5,100)
y=np.exp(-x**2)
plot(x,y,"-.^k",label="$y=e^{-x^2}$")
xlabel=("x-axis")
ylabel=("y-axis")
title("Graph of f(x)")
legend()
show()Output:-
Q4:- 4. Plot the graph of (𝑥) = sin 𝑥 and (𝑥) = cos 𝑥 in [−2𝜋, 2𝜋] with legend at upper left corner.
import numpy as np
x=np.linspace(-2*pi,2*pi,100)
f1=np.sin(x)
f2=np.cos(x)
plot(x,f1,label="$\sinx$")
plot(x,f2,label="$\cosx$")
legend(loc=2)
show()
Output:-
5. Generate a subplot for the following functions using the Python. i. 𝑦 = 𝑒 −𝑥 sin , = 𝑒 −2𝑥 cos 𝑥 ; 0 ≤ 𝑥 ≤ 4𝜋 (2 × 1
subplots ) ii. 𝑦 = 1 , = 1 𝑥 2 , 𝑦 = 1 𝑥 3 ; −5 ≤ 𝑥 ≤ 5 (1 × 3) subplots
Program:-
import numpy as np
x=np.linspace(0,4*pi,100)
y1=exp(-x)*sin(x)
y2=exp(-2*x)*cos(x)
subplot(2,1,1)
plot(x,y1,label="$\exp(-x)*sin(x)$")
legend()
subplot(2,1,2)
plot(x,y2,label="$\exp(-2*x)*cos(x)$")
legend()
show()
Output:-
II)Program:-
import numpy as np
x=np.linspace(-5,5,100)
y1=1/x
y2=1/x**2
y3=1/x**3
plt.subplot(1,3,1)
plt.plot(x,y1,label='$y1=\dfrac{1}{x}$')
plt.legend()
plt.subplot(1,3,2)
plt.plot(x,y2,label="$y2=\dfrac{1}{x^2}$")
plt.legend()
plt.subplot(1,3,3)
plt.plot(x,y3,label='$y3=\dfrac{1}{x^3}$')
plt.legend()
plt.show()
output:-
Q.1) 1. Generate 3D Contour Plots for the following functions using the Python.𝑦 = sin(𝑥 + 𝑦) , −2𝜋 ≤ 𝑥 ≤ 2 𝜋
Program:-
import numpy as np
def f(x,y):
return np.sin(x+y)
x=np.linspace(-2*pi,2*pi,100)
y=np.linspace(-2*pi,2*pi,100)
X,Y=np.meshgrid(x,y)
z=f(X,Y)
ax=axes(projection='3d')
ax.contour3D(x,y,z,50)
xlabel('X-axis')
ylabel('Y-axis')
title('3D contour')
show()
Output:-
Q 1.)ii. 𝑦 = 𝑥 3 + 𝑦 2 , −5 ≤ 𝑥 ≤ 5
Program:-
import numpy as np
x,y=symbols('x y')
def f(x,y):
return x**3+y**3
x=np.linspace(-5,5,100)
y=np.linspace(-5,5,100)
X,Y=np.meshgrid(x,y)
z=f(X,Y)
ax=axes(projection='3d')
ax.contour3D(x,y,z,50)
xlabel('X-axis')
ylabel('Y-axis')
title('3D contour')
show()
output:-
Q .2)Generate 3D wireframe Plot for the function (𝑥) = 𝑒𝑥 2+𝑦 2 in the interval [0,2𝜋].
Program:-
import numpy as np
x,y=symbols('x y')
def f(x,y):
return np.exp(x**2+y**2)
x=np.linspace(0,2*pi,100)
y=np.linspace(0,2*pi,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=axes(projection='3d')
ax.plot_wireframe(X,Y,Z,rstride=3,cstride=3)
xlabel('X-axis')
ylabel('Y-axis')
title('3D wireframe')
show()
Output:-
Q.3)Generate 3D wireframe Plot for the function (𝑥) = sin(𝑥) + cos(𝑦) in the interval [−5,5]
Program:-
from mpl_toolkits import mplot3d
import numpy as np
x,y=symbols('x y')
def f(x,y):
return np.sin(x)+np.cos(y)
x=np.linspace(-5,5,100)
y=np.linspace(-5,5,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=axes(projection='3d')
ax.plot_wireframe(X,Y,Z,rstride=5,cstride=5)
xlabel('X-axis')
ylabel('Y-axis')
title('3D wireframe')
show()
Output:-
Q.4)Generate 3D Surface Plot for the function (𝑥) = 𝑥𝑒−𝑥 2−𝑦 2 in the interval [−6,6].
Program:-
import numpy as np
x,y=symbols('x y')
def f(x,y):
return x*np.exp(-x**2-y**2)
x=np.linspace(-6,6,100)
y=np.linspace(-6,6,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=axes(projection='3d')
ax.plot_surface(X,Y,Z)
xlabel('X-axis')
ylabel('Y-axis')
title('3D Surface')
show() output:-
Q.5)Generate 3D Surface Plot for the function (𝑥) = 𝑥 3 + 𝑦 3 + 𝑥 2 + 𝑦 2 + 𝑥 + 𝑦 + 5 in the interval [−2,2]
Program:-
import numpy as np
x,y=symbols('x y')
def f(x,y):
return x**3+y**3+x**2+y**2+x+y+5
x=np.linspace(-2,2,100)
y=np.linspace(-2,2,100)
X,Y=np.meshgrid(x,y)
Z=f(X,Y)
ax=axes(projection='3d')
ax.plot_surface(X,Y,Z)
xlabel('X-axis')
ylabel('Y-axis')
title('3D surface')
show()
output:-
0…………………… Q.1)Generate following points using python.
A= (3,4)
B= (5,-7)
C= (0.4,0.9)
Q= (7/2,5/2)
OUTPUT:
A=Point(3,4)
Point2D(3, 4)
B=Point(5,-7)
Point2D(5, -7)
C=Point(0.4,0.9)
Point2D(2/5, 9/10)
Q=Point(7/2,5/2)
Point2D(7/2, 5/2)
Q.2)Find the distance between points 𝑥, ; 𝑦, 𝑤 and 𝑥, 𝑧 , if 𝑥 = [0,0], 𝑦 = [2,2], 𝑧 = [−1, −1] and 𝑤 = [3,4].
OUTPUT:
x=Point(0,0)
y=Point(2,2)
z=Point(-1,-1)
w=Point(3,4)
x.distance(y)
2*sqrt(2)
y.distance(w)
sqrt(5)
x.distance(z)
sqrt(2)
Q.3) Generate points 𝑃 = (4, −8), = (3, −5.3) and = (7.7,10) , check if they are collinear.
P=Point(4,-8)
P=Point(4,-8)
P=Point(4,-8)
Q=Point(3,-5.3)
R=Point(7.7,10)
Point.is_collinear(P,Q,R)
OUTPUT:
False
Q.4)Generate points 𝑎 = (3,2), 𝑏 = (5, −5), 𝑐 = (0, −6) and 𝑑 = (10, −10) , check if they are coplanar.
a=Point(3,2)
b=Point(5,-5)
c=Point(0,-6)
d=Point(10,-10)
Point.are_coplanar(a,b,c,d)
OUTPUT:
True
Q.5). Plot point 𝑋 = (−8,8) in python using matplotlib
x=[-8]
y=[8]
plt.plot(x,y,marker='o')
xlabel('X label')
ylabel('Y label')
title('Graph of X')
plt.show()
GRAPH:
Q.1)
1)=>
L=Line(Point(1,5),Point(9,5.1))
L
Line2D(Point2D(1, 5), Point2D(9, 51/10))
2)=>
M=Line(2*x+3*y-6)
3)=>
N=Line(Point(2,6),slope=3)
4)=>
S=Segment((0,0),(6,6))
5)=>
R=Ray((0,0),(4,4))
Q.2)=>
S=Segment((1,4),(7,14))
m=S.length
n=S.midpoint
OUTPUT:
x,y=symbols('x y')
L=Line(3*x+4*y-5)
a=L.slope
OUTPUT:
Q.4)
x,y=symbols('x y')
L=Line((0,0),(0,3))
R=Ray((0,0),(8,8))
a=L.angle_between(R)
OUTPUT:
Q.5)
L=Line((0,8),(8,0))
S=Segment((0,0),(10,10))
a=L.intersection(S)
OUTPUT:
Intersection of line and segment is [Point2D(4, 4)]
Qno.1)
A=Polygon((0,0),(1,0),(5,1),(0,1),(3,0))
p=A.area
q=A.perimeter
Q.no.2)
A=Polygon((0,0),5,n=8)
a=A.area
b=A.perimeter
Qno.3)
i)
T1=Triangle(sss=(3,4,5))
T1
Output : Triangle(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))
ii)
T2=Triangle(sas=(1,30,2))
T2
iii)
v1,v2,v3=[(0,0),(1,0),(5,1)]
T3=Triangle(v1,v2,v3)
T3
Q.no.4)
p1,p2,p3=[(0,0),(4,0),(2,4)]
T4=Triangle(p1,p2,p3)
T4.is_isosceles()
Output : True
Q.no.5)
a1,a2,a3=[(0,0),(4,0),(4,3)]
T5=Triangle(a1,a2,a3)
T5.is_right()
Output : True
Q.no.6)
b1,b2,b3=[(0,0),(4,0),(1,4)]
T6=Triangle(b1,b2,b3)
T6.is_scalene()
Output : True
Q1. Apply each of the following transformation on the point [−2 3.5].
Program:-
x=Point(-2,3.5)
A=x.transform(Matrix([[0,-1,0],[-1,0,0],[0,0,1]]))
angle=radians(57)
B=x.rotate(angle)
C=x.scale(3,3)
D=x.transform(Matrix([[1,0,0],[2,1,0],[0,0,1]]))
print('Shearing in y direction by 2 units is',D)
E=x.transform(Matrix([[-1,0,0],[0,-1,0],[0,0,1]]))
Program:-
x=Point(3,-1)
A=x.transform(Matrix([[1,0,0],[0,1,0],[0,0,1]]))
B=x.scale(2,0)
C=x.scale(0,1.5)
angle=radians(30)
D=x.rotate(angle)
E=x.transform(Matrix([[1,4,0],[-2,1,0],[0,0,1]]))
Output:-
Q1.
Program:-
s1=Segment((1,0),(2,-1))
a1=s1.rotate(pi)
print(a1)
OUTPUT:-
Q2.
Program:-
x,y=symbols('x y')
r=Ray((0,0),(2,4))
l=Line(x-2*y-3)
a=r.reflect(l)
print(a)
OUTPUT:-
Q3.
Program:-
l=Line((0,0),(0,1))
a=l.rotate(pi/2)
b=l.equation()
print(a)
print(b)
OUTPUT:-
Q4.
Program:-
x,y=symbols('x y')
l=Line(4*x+3*y-5)
m=Line(x+y)
n=l.reflect(m)
a=n.equation()
Q5.
Program:-
x,y=symbols('x y')
A=Point(5,3)
B=Point(1,4)
l=Line(A,B)
l=Line(y-x-1)
a=l.reflect(l)
print(a)
OUTPUT:-
Q1:-
x,y=symbols('x y')
l1=Line(2*x-y-5)
l2=Line(x+3*y+1)
p=l1.intersection(l2)
p=p[0]
q=p.transform(Matrix([[-2,1,0],[3,1,0],[0,0,-1]]))
Output:-
Program:-
x,y=symbols('x y')
A=Point(-1,8)
B=Point(5,-6)
A1=A.transform(Matrix([[3,5,0],[-1,3,0],[0,0,1]]))
B1=B.transform(Matrix([[3,5,0],[-1,3,0],[0,0,1]]))
S=Segment(A1,B1)
a=S.slope
Output:-
Q3
Program:-
x,y=symbols('x y')
l=Line(y-x-4)
T=Matrix([[1,-2,0],[3,2,0],[0,0,1]])
points=l.points
p=points[0]
q=points[1]
s=T.inv()
p1=p.transform(s)
q1=q.transform(s)
l1=Line(p1,q1)
print(l1.equation())
Output:-
-3*x/8 - y/8 - ½
Q4
x,y=symbols('x y')
l=Line(2*x+y-3)
points=l.points
p=points[0]
q=points[1]
M=Matrix([[1,-3,0],[2,1,0],[0,0,1]])
p1=p.transform(M)
q1=q.transform(M)
l1=Line(p1,q1)
print(l1.equation())
Output:-
5*x - 3*y – 21
Q5
Program:-
x,y=symbols('x y')
A=Point(-2,5)
B=Point(4,3)
A1=A.transform(Matrix([[2,4,0],[2,-1,0],[0,0,1]]))
B1=B.transform(Matrix([[2,4,0],[2,-1,0],[0,0,1]]))
S=Segment(A1,B1)
a=S.midpoint
Output:-
Q1.
Program:-
p1,p2,p3,p4=map(Point,((0,0),(1,0),(2,2),(1,4)))
p=Polygon(p1,p2,p3,p4)
Area=p.area
print(Area)
perimeter=p.perimeter
print(perimeter)
p1=Polygon((2,2),5,n=8)
Area1=p1.area
print(Area)
perimeter1=p1.perimeter
print(perimeter)
OUTPUT:-
1 + sqrt(17) + 2*sqrt(5)
1 + sqrt(17) + 2*sqrt(5)
Q2.
Program:-
x,y=symbols('x y')
l=Line(y-3)
A,B,C=map(Point,[(1,1),(2,-3),(-1,5)])
p=Polygon(A,B,C)
r=p.reflect(l)
print(r)
OUTPUT:-
Q3.
Program:-
A,B,C=map(Point,[(1,1),(1,2),(0,1)])
p=Polygon(A,B,C)
print(p.angles[A])
print(p.angles[B])
print(p.angles[C])
OUTPUT:-
pi/2
pi/4
pi/4
Q4.
Program:-
A=Point(0,0)
B=Point(-2,0)
C=Point(5,5)
D=Point(1,-6)
p=Polygon(A,B,C,D)
print(p.rotate(pi))
print(p.angles[A])
print(p.angles[B])
print(p.angles[C])
print(p.angles[D])
OUTPUT:-
acos(-sqrt(37)/37)
acos(7*sqrt(74)/74) + 2*pi
acos(83*sqrt(10138)/10138) + 2*pi
acos(62*sqrt(5069)/5069) + 2*pi
Q5.
Program:-
A=Point(1,-2)
B=Point(4,-6)
C=Point(-1,4)
p=Triangle(A,B,C)
print(p.rotate(pi/2))
print(p.angles[A])
print(p.angles[B])
print(p.angles[C])
OUTPUT:-
acos(-3*sqrt(10)/10)
acos(11*sqrt(5)/25)
acos(7*sqrt(2)/10)
Q1.
Program:-
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
model+=(4*x+6*y<=24)
model+=(5*x+3*y<=15)
model+=150*x+75*y
print(model)
print(model.solve())
OUTPUT:-
Small_Problem_:
MAXIMIZE
150*x + 75*y + 0
SUBJECT TO
_C1: 4 x + 6 y <= 24
_C2: 5 x + 3 y <= 15
VARIABLES
x Continuous
y Continuous
Q2.
Program:-
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
model+=(x>=6)
model+=(y>=6)
model+=x+y<=11
print(model)
print(model.solve())
OUTPUT:-
Small_Problem_:
MINIMIZE
None
SUBJECT TO
_C1: x >= 6
_C2: y >= 6
_C3: x + y <= 11
VARIABLES
x Continuous
y Continuous
Q3.
Program:-
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
model+=(x>=1)
model+=(y>=2)
model+=x+y
print(model)
print(model.solve())
OUTPUT:_
Small_Problem_:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x >= 1
_C2: y >= 2
VARIABLES
x Continuous
y Continuous
-2