Slips 1-5 Slides
Slips 1-5 Slides
In [ ]:
In [1]:
In [ ]:
(b) Write a Python program to plot 3D graph of the function f(x) = e^(−x^2)
in [−5, 5] with green dashed points line with upward pointing triangle.
In [4]:
In [ ]:
(c) Using python, represent the following information using a bar graph (in green color )
Item clothing Food rent Petrol Misc.
expenditure in Rs 600 4000 2000 1500 700
In [5]:
In [ ]:
In [41]:
In [9]:
x,y=symbols('x,y')
A=Point(5,3)
B=Point(1,4)
S=Segment(A,B)
S.reflect(Line(x-y+1))
Out[9]:
In [ ]:
(b) Write a Python program to draw a polygon with vertices (0, 0),(2, 0),(2, 3) and (1, 6) and
it by 180◦
In [10]:
A=Point(0,0)
B=Point(2,0)
C=Point(2,3)
D=Point(1,6)
P=Polygon(A,B,C,D)
P.rotate(pi)
Out[10]:
In [ ]:
(c) Write a Python program to find the area and perimeter of the ∆ABC, where A[0, 0], B[5, 0],
In [11]:
A=Point(0,0)
B=Point(5,0)
C=Point(3,3)
T=Triangle(A,B,C)
In [12]:
T.area
Out[12]:
15
In [13]:
T.perimeter
Out[13]:
√13 + 3√2 + 5
In [ ]:
In [14]:
Out[14]:
Lp-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
In [15]:
model.solve()
Out[15]:
In [16]:
model.objective.value()
Out[16]:
450.0
In [17]:
x.value()
Out[17]:
3.0
In [18]:
y.value()
Out[18]:
0.0
In [ ]:
(ii) Write a python program to display the following LPP by using pulp module and simplex
method. Find its optimal solution if exist.
Min Z = x + y
subject to
x ≥ 6
y ≥ 6
x + y ≤ 11
x ≥ 0, y ≥ 0.
In [21]:
Out[21]:
Lp-Problem:
MINIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x >= 6
_C2: y >= 6
_C3: x + y <= 11
VARIABLES
x Continuous
y Continuous
In [22]:
model.solve()
Out[22]:
-1
In [ ]:
In [23]:
P=Point(3,-1)
In [24]:
P.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]]))
Out[24]:
Point2D(3, 1)
In [25]:
P.scale(2,0)
Out[25]:
Point2D(6, 0)
In [26]:
P.scale(0,1.5)
Out[26]:
3
Point2D(0, − )
2
In [27]:
x,y=symbols('x,y')
P.reflect(Line(x-y+0))
Out[27]:
Point2D(−1, 3)
In [ ]:
(ii) Find the combined transformation of the line segment between the points A[5, −2] & B[4, 3]
by using Python program for the following sequence of transformations:-
(I) Rotation about origin through an angle π.
(II) Scaling in X− coordinate by 2 units.
(III) Reflection through the line y = −x.
(IV) Shearing in X direction by 4 units.
In [28]:
A=Point(5,-2)
B=Point(4,3)
S=Segment(A,B)
S=S.rotate(pi)
S=S.scale(2,0)
points=S.points
p=points[0]
q=points[1]
p1=p.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
q1=q.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
Segment(p1,q1)
p1=p.transform(Matrix([[1,4,0],[0,1,0],[0,0,1]]))
q1=q.transform(Matrix([[1,4,0],[0,1,0],[0,0,1]]))
Segment(p1,q1)
Out[28]:
In [ ]:
In [ ]:
In [32]:
C:\Users\siddhi\AppData\Local\Temp\ipykernel_3592\1816612830.py:4: RuntimeWar
ning: divide by zero encountered in log10
f=np.log10(x)
In [ ]:
(b) Using python, generate 3D surface Plot for the function f(x) = sin(x^2 + y^2) in the interv
In [34]:
In [ ]:
(c) Using python, draw a bar graph in GREEN colour to represent the data below:
Subject Maths Science English Marathi Hindi
Percentage of passing 68 90 70 85 91
In [35]:
In [ ]:
(a) Using sympy declare the points A(0, 2), B(5, 2), C(3, 0) check whether these points are col
In [36]:
A=Point(0,2)
B=Point(5,2)
C=Point(3,0)
In [37]:
Point.is_collinear(A,B,C)
Out[37]:
False
In [38]:
L=Line(A,B)
In [40]:
L.distance(C)
Out[40]:
In [ ]:
(b) Using python, drawn a regular polygon with 6 sides and radius 1 centered at (1, 2) and find
area and perimeter.
In [44]:
P=Polygon((1,2),1,n=6)
In [45]:
P.area
Out[45]:
3√ 3
In [46]:
P.perimeter
Out[46]:
In [ ]:
(c) Write a Python program to find the area and perimeter of the ∆ABC, where A[0, 0], B[6, 0],
In [47]:
A=Point(0,0)
B=Point(6,0)
C=Point(4,4)
T=Triangle(A,B,C)
In [48]:
T.area
Out[48]:
12
In [49]:
T.perimeter
Out[49]:
2√5 + 4√2 + 6
In [ ]:
In [50]:
Out[50]:
Lp-Problem:
MAXIMIZE
5*x + 3*y + 0
SUBJECT TO
_C1: x + y <= 7
_C2: 2 x + 5 y <= 1
VARIABLES
x Continuous
y Continuous
In [51]:
model.solve()
Out[51]:
In [52]:
model.objective.value()
Out[52]:
2.5
In [53]:
x.value()
Out[53]:
0.5
In [54]:
y.value()
Out[54]:
0.0
In [ ]:
(ii) Write a python program to display the following LPP by using pulp module and simplex
method. Find its optimal solution if exist.
Max Z = 3x + 2y + 5z
subject to
x + 2y + z ≤ 430
3x + 2z ≤ 460
x + 4y ≤ 120
x ≥ 0, y ≥ 0, z ≥ 0.
In [55]:
Out[55]:
Lp-Problem:
MAXIMIZE
3*x + 2*y + 5*z + 0
SUBJECT TO
_C1: x + 2 y + z <= 430
VARIABLES
x Continuous
y Continuous
z Continuous
In [56]:
model.solve()
Out[56]:
In [57]:
model.objective.value()
Out[57]:
1210.0
In [58]:
x.value()
Out[58]:
0.0
In [59]:
y.value()
Out[59]:
30.0
In [60]:
z.value()
Out[60]:
230.0
In [ ]:
In [61]:
P=Point(4,-2)
In [63]:
In [65]:
P.transform(Matrix([[-1,0,0],[0,1,0],[0,0,1]]))
Out[65]:
Point2D(−4, −2)
In [66]:
P.scale(3,0)
Out[66]:
Point2D(12, 0)
In [67]:
P.scale(0,2.5)
Out[67]:
Point2D(0, −5)
In [69]:
x,y=symbols('x,y')
P.reflect(Line(x+y+0))
Out[69]:
Point2D(2, −4)
In [ ]:
(ii) Find the combined transformation of the line segment between the points A[4, −1] & B[3, 0]
by using Python program for the following sequence of transformations:-
(I) Rotation about origin through an angle π.
(II) Shearing in Y direction by 4.5 units.
(III) Scaling in X− coordinate by 3 units.
(IV) Reflection through the line y = x.
In [70]:
A=Point(4,-1)
B=Point(3,0)
S=Segment(A,B)
S=S.rotate(pi)
points=S.points
p=points[0]
q=points[1]
p1=p.transform(Matrix([[1,0,0],[4.5,1,0],[0,0,1]]))
q1=q.transform(Matrix([[1,0,0],[4.5,1,0],[0,0,1]]))
Segment(p1,q1)
S.scale(3,0)
p1=p.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
q1=q.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
Segment(p1,q1)
Out[70]:
In [ ]:
In [ ]:
In [1]:
In [ ]:
(b) Following is the information of students participating in various games in a school. Repres
by a Bar graph with bar width of 0.7 inches.
Game Cricket Football Hockey Chess Tennis
Number of students 65 30 54 10 20
In [5]:
In [ ]:
(c) Write a Python program to generate 3D plot of the functions z = sin x + cos y in −10 < x, y
In [6]:
In [ ]:
In [9]:
A=Point(5,3)
B=Point(1,4)
S=Segment(A,B)
x,y=symbols('x,y')
S.reflect(Line(x-y+1))
Out[9]:
In [ ]:
(b) If the line with points A[2, 1], B[4, −1] is transformed by the transformation matrix [T] =
then using python, find the equation of transformed line.
In [12]:
A=Point(2,1)
B=Point(4,-1)
A1=A.transform(Matrix([[1,2,0],[2,1,0],[0,0,1]]))
B1=B.transform(Matrix([[1,2,0],[2,1,0],[0,0,1]]))
L=Line(A1,B1)
L.equation()
Out[12]:
−2x − 2y + 18
In [ ]:
(c) Generate line segment having endpoints (0, 0) and (10, 10) find midpoint of line segment.
In [13]:
A=Point(0,0)
B=Point(10,10)
L=Segment(A,B)
L.midpoint
Out[13]:
Point2D(5, 5)
In [ ]:
In [14]:
Out[14]:
Lp-Problem:
MINIMIZE
3.5*x + 2*y + 0.0
SUBJECT TO
_C1: x + y >= 5
_C2: x >= 4
_C3: y <= 2
VARIABLES
x Continuous
y Continuous
In [17]:
model.solve()
Out[17]:
In [18]:
model.objective.value()
Out[18]:
16.0
In [19]:
x.value()
Out[19]:
4.0
In [20]:
y.value()
Out[20]:
1.0
In [ ]:
(ii) Write a python program to display the following LPP by using pulp module and simplex
method. Find its optimal solution if exist.
Max Z = 3x1 + 5x2 + 4x3
subject to
2x1 + 3x2 ≤ 8
2x2 + 5x3 ≤ 10
3x1 + 2x2 + 4x3 ≤ 15
x1 ≥ 0, x2 ≥ 0, x3 ≥ 0.
In [21]:
Out[21]:
Lp-Problem:
MAXIMIZE
3*x1 + 5*x2 + 4*x3 + 0
SUBJECT TO
_C1: 2 x1 + 3 x2 <= 8
_C2: 2 x2 + 5 x3 <= 10
_C3: 3 x1 + 2 x2 + 4 x3 <= 15
VARIABLES
x1 Continuous
x2 Continuous
x3 Continuous
In [22]:
model.solve()
Out[22]:
In [23]:
model.objective.value()
Out[23]:
18.658536500000004
In [25]:
x1.value()
Out[25]:
2.1707317
In [26]:
x2.value()
Out[26]:
1.2195122
In [27]:
x3.value()
Out[27]:
1.5121951
In [ ]:
In [28]:
P=Point(4,-2)
In [31]:
P.transform(Matrix([[-1,0,0],[0,1,0],[0,0,1]]))
Out[31]:
Point2D(−4, −2)
In [32]:
P.scale(3,0)
Out[32]:
Point2D(12, 0)
In [33]:
P.scale(0,2.5)
Out[33]:
Point2D(0, −5)
In [34]:
x,y=symbols('x,y')
P.reflect(Line(x+y+0))
Out[34]:
Point2D(2, −4)
In [ ]:
(ii) Find the combined transformation of the line segment between the points A[2, −1] & B[5, 4]
by using Python program for the following sequence of transformations:-
(I) Rotation about origin through an angle π.
(II) Scaling in X−coordinate by 3 units.
(III) Shearing in X direction by 6 units.
(IV) Reflection through the line y = x.
In [35]:
A=Point(2,-1)
B=Point(5,4)
S=Segment(A,B)
S.rotate(pi)
Out[35]:
In [ ]:
In [36]:
C:\Users\siddhi\AppData\Local\Temp\ipykernel_6912\1816612830.py:4: RuntimeWar
ning: divide by zero encountered in log10
f=np.log10(x)
In [ ]:
(b) Using Python plot the graph of function f(x) = sin^−1(x) on the interval [−1, 1].
In [37]:
In [ ]:
(c) Using Python plot the surface plot of parabola z = x^2 + y^2
in −6 < x, y < 6.
In [39]:
In [ ]:
In [43]:
A=Point(3,1)
B=Point(5,-1)
A1=A.transform(Matrix([[3,-2,0],[2,1,0],[0,0,1]]))
B1=B.transform(Matrix([[3,-2,0],[2,1,0],[0,0,1]]))
L=Line(A1,B1)
L.equation()
Out[43]:
6x + 2y − 56
In [ ]:
(b) Write a Python program to draw a polygon with vertices (0, 0),(2, 0),(2, 3) and (1, 6) and
it by 180◦
In [44]:
A=Point(0,0)
B=Point(2,0)
C=Point(2,3)
D=Point(1,6)
P=Polygon(A,B,C,D)
P.rotate(pi)
Out[44]:
In [ ]:
(c) Using python, generate line passing through points (2, 3) and (4, 3) and find equation of t
In [45]:
A=Point(2,3)
B=Point(4,3)
L=Line(A,B)
L.equation()
Out[45]:
y − 3
In [ ]:
In [48]:
Out[48]:
Lp-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
In [49]:
model.solve()
Out[49]:
In [50]:
model.objective.value()
Out[50]:
450.0
In [51]:
x.value()
Out[51]:
3.0
In [52]:
y.value()
Out[52]:
0.0
In [ ]:
(ii) Write a python program to display the following LPP by using pulp module and simplex
method. Find its optimal solution if exist.
Max Z = 4x + y + 3z + 5w
subject to
4x + 6y − 5z − 4w ≥ −20
−8x − 3y + 3z + 2w ≤ 20
In [53]:
Out[53]:
Lp-Problem:
MAXIMIZE
5*w + 4*x + 1*y + 3*z + 0
SUBJECT TO
_C1: - 4 w + 4 x + 6 y - 5 z >= -20
_C2: 2 w - 8 x - 3 y + 3 z <= 20
_C3: x + y <= 11
VARIABLES
w Continuous
x Continuous
y Continuous
z Continuous
In [54]:
model.solve()
Out[54]:
In [55]:
model.objective.value()
Out[55]:
124.0
In [56]:
x.value()
Out[56]:
11.0
In [57]:
y.value()
Out[57]:
0.0
In [58]:
z.value()
Out[58]:
0.0
In [59]:
w.value()
Out[59]:
16.0
In [ ]:
In [60]:
In [ ]:
(ii) Find the combined transformation of the line segment between the points A[4, −1] & B[3, 0]
by using Python program for the following sequence of transformations:-
(I) Shearing in X direction by 9 units.
(II) Rotation about origin through an angle π.
(III) Scaling in X− coordinate by 2 units.
(IV) Reflection through the line y = x.
In [61]:
A=Point(4,-1)
B=Point(3,0)
S=Segment(A,B)
points=S.points
p=points[0]
q=points[1]
p1=p.transform(Matrix([[1,9,0],[0,1,0],[0,0,1]]))
q1=q.transform(Matrix([[1,9,0],[0,1,0],[0,0,1]]))
Segment(p1,q1)
S.rotate(pi)
S.scale(2,0)
p1=p.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
q1=q.transform(Matrix([[0,1,0],[1,0,0],[0,0,1]]))
Segment(p1,q1)
Out[61]:
In [ ]:
In [62]:
Out[62]:
In [ ]:
(b) Generate 3D surface Plot for the function f(x) = sin(x^2 + y^2) in the interval [0, 10].
In [63]:
In [ ]:
(c) Write a Python program to generate 3D plot of the functions z = sin x + cos y in the interv
−10 < x, y < 10.
In [68]:
In [ ]:
In [74]:
A=Point(0,0)
B=Point(4,0)
C=Point(4,3)
T=Triangle(A,B,C)
T.is_right()
Out[74]:
True
In [75]:
T=Triangle(Point(0,0),Point(4,0),(4,3))
T.is_right()
Out[75]:
True
In [ ]:
(b) Generate vector x in the interval [−7, 7] using numpy package with 50 subintervals.
In [76]:
import numpy as np
x=np.linspace(-7,7,50)
print(x)
In [ ]:
(c) Write a Python program to find the area and perimeter of the ∆ABC, where A[0, 0], B[6, 0],
In [77]:
T=Triangle(Point(0,0),Point(6,0),Point(4,4))
T.area
Out[77]:
12
In [78]:
T.perimeter
Out[78]:
2√5 + 4√2 + 6
In [ ]:
In [81]:
Out[81]:
Lp-Problem:
MAXIMIZE
5*x + 3*y + 0
SUBJECT TO
_C1: x + y <= 7
_C2: 2 x + 5 y <= 1
VARIABLES
x Continuous
y Continuous
In [82]:
model.solve()
Out[82]:
In [83]:
model.objective.value()
Out[83]:
2.5
In [84]:
x.value()
Out[84]:
0.5
In [85]:
y.value()
Out[85]:
0.0
In [ ]:
(ii) Write a python program to display the following LPP by using pulp module and simplex
method. Find its optimal solution if exist.
Max Z = 4x + y + 3z + 5w
subject to
4x + 6y − 5z − 4w ≥ 20
−3x − 2y + 4z + w ≤ 10
−8x − 3y + 3z + 2w ≤ 20
x + y ≤ 11
x ≥ 0, y ≥ 0, z ≥ 0, w ≥ 0.
In [86]:
Out[86]:
Lp-Problem:
MAXIMIZE
5*w + 4*x + 1*y + 3*z + 0
SUBJECT TO
_C1: - 4 w + 4 x + 6 y - 5 z >= 20
_C2: w - 3 x - 2 y + 4 z <= 10
_C3: 2 w - 8 x - 3 y + 3 z <= 20
_C4: x + y <= 11
VARIABLES
w Continuous
x Continuous
y Continuous
z Continuous
In [87]:
model.solve()
Out[87]:
In [88]:
model.objective.value()
Out[88]:
74.0
In [89]:
x.value()
Out[89]:
11.0
In [90]:
y.value()
Out[90]:
0.0
In [91]:
z.value()
Out[91]:
0.0
In [92]:
w.value()
Out[92]:
6.0
In [ ]:
In [93]:
P=Point(3,8)
In [95]:
P.transform(Matrix([[1,0,0],[0,-1,0],[0,0,1]]))
Out[95]:
Point2D(3, −8)
In [96]:
P.scale(6,0)
Out[96]:
Point2D(18, 0)
In [97]:
P.rotate(pi/6)
Out[97]:
35048094716167 842820323027551
Point2D(− , )
25000000000000 100000000000000
In [98]:
P.transform(Matrix([[0,-1,0],[-1,0,0],[0,0,1]]))
Out[98]:
Point2D(−8, −3)
In [ ]:
(ii) Write a python program to Plot 2D X−axis and Y−axis in black colour. In the same diagram
plot:-
(I) Green triangle with vertices [5, 4], [7, 4], [6, 6].
(II) Blue rectangle with vertices [2, 2], [10, 2], [10, 8], [2, 8].
In [100]:
Out[100]:
[<matplotlib.patches.Polygon at 0x2c58920fcd0>]
In [ ]: