Practical 12
Practical 12
12
MTC-243: Mathematics Practical: Python Programming Language II
x = np.linspace(-10,10,1000)
f = 3*x**4 + 2*x**3 + 7*x**2 + 2*x + 9
g = 5*x**3 + 9*x + 2
plot(x,f,label="$f(x)$")
plot(x,g,label="$f(g)$")
xlabel('x')
ylabel('y')
legend()
show()
2. Using sympy declare the points P(5, 2), Q(5, −2), R(5, 0), check whether
these points are collinear. Declare the ray passing through the points P
and Q, find the length of this ray between P and Q. Also find slope of this
ray.
➢ from sympy import *
P=Point(5,2)
Q=Point(5,-2)
R=Point(5,0)
print(Point.is_collinear(P,Q,R))
S=Ray(P,Q)
print(S.length)
print(S.slope)
𝑥
(− )
3. Plot the graph of f(x)=𝑒 2 𝑠𝑖𝑛(2𝜋) in [-5,5].
➢ from pylab import *
import matplotlib.pyplot as pylot
import numpy as np
x=np.linspace(-5,5)
f=(np.e**(-x/2))*(np.sin(2*np.pi))
plot(x,f)
show()
4. Write a program to solve the following LPP :
Min Z = 3.5x + 2y
subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0.
➢ from pulp import *
model=LpProblem(sense=LpMinimize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
model+=3.5*x + 2*y
model.solve()
P=Point(-2,4)
x,y=symbols('x y')
print(P.reflect(Line(3*x+4*y-5)))
print(P.scale(6,0))
print(P.scale(0,4.1))
print(P.reflect(Line(-2*x+y-3)))
print(P.transform(Matrix([[1,0,0],[7,1,0],[0,0,1]])))
print(P.scale(7/2,4))
print(P.transform(Matrix([[1,4,0],[7,1,0],[0,0,1]])))
angle=radians(48)
print(P.rotate(angle))
6. Represent the following information using a bar graph (in green color).
Item Clothing Food Rent Petrol Misc
Expenditure 600 4000 2000 1500 700
subject=['Cloths','Food','Rent','Petrol','Misc']
percentage=[600,4000,2000,1500,700]
plt.bar(subject,percentage,color='green')
plt.xlabel('subject')
plt.ylabel('percentage')
show()
7. Write a Python program with vertices (0, 0),(1, 0),(2, 2),(1, 4). Also find
area and perimeter of the polygon.
➢ from sympy import *
A=Point(0,0)
B=Point(1,0)
C=Point(2,2)
D=Point(1,4)
P=Polygon(A,B,C,D)
print(P.area)
print(P.perimeter)