[go: up one dir, main page]

0% found this document useful (0 votes)
12 views5 pages

Practical 12

The document contains 7 math and programming problems. It provides Python code to plot graphs, check collinear points, apply transformations, represent data in a bar graph, and calculate the area and perimeter of a polygon.

Uploaded by

shivrajarande341
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)
12 views5 pages

Practical 12

The document contains 7 math and programming problems. It provides Python code to plot graphs, check collinear points, apply transformations, represent data in a bar graph, and calculate the area and perimeter of a polygon.

Uploaded by

shivrajarande341
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/ 5

MATHEMATICS PRACTICAL NO.

12
MTC-243: Mathematics Practical: Python Programming Language II

1. Plot the graph of two polynomials in [-10,10].


F(x) = 3𝑥 4 + 2𝑥 3 + 7𝑥 2 + 2x + 9
G(x) = 5𝑥 3 + 9x + 2
➢ from pylab import *
import matplotlib.pyplot as plt
import numpy as np

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+=(x + y >= 15)


model+=(x >= 4)
model+=(y <= 2)

model+=3.5*x + 2*y
model.solve()

print("The value of objective function


is",model.objective.value())
print("The value of x is",x.value())
print("The value of y is",y.value())

5. Apply each of the following transformations the point point P=[-2,4].


i. Reflection through line 3x + 4y = 5.
ii. Scaling in X - coordinate by factor 6.
iii. Scaling in Y – coordinate by factor 4.1.
iv. Reflection through the line y = 2x + 3.
v. Shearing in Y direction by 7 units.
vi. Scaling in X and Y direction by 7/2 and 4 units respectively.
vii. Shearing in both X and Y direction by 4 and 7 unit respectively.
viii. Rotation about origin by an angle 48 degrees
➢ from sympy import *
from math import *

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

➢ import matplotlib.pyplot as plt


from pylab import *

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)

You might also like