Slip NO - 1
Slip NO - 1
In [1]: #Q1) Write a Python program to plot 2D graph of the functions f(x) = x^2 a
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 100)
y1 = x**2
y2 = x**3
1 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [2]: #Q2) Write a Python program to plot 3D graph of the function f(x) = e−x2 i
# points line with upward pointing triangle.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.linspace(-5, 5, 100)
y = np.exp(-x) ** 2
ax.plot(x, y, zs=0, zdir='z', color='g', linestyle='--', marker='^')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('f(x)')
plt.show()
2 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [3]: #Q3 using python represent the following information using a bar graph (in
# Item Clothing food Rent Petrol Misc.
# Expenditure in Rs 600 4000 2000 1500 700
3 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [4]: #Q4)write a python, program to reflect the line segment joining the point A
import numpy as np
4 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
plt.show()
5 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
6 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [6]: #Q6)write a python program to find the area and perimeter of Triangle ABC w
import math
7 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [7]: #Q8)write a python program to display the following LPP by using pulp modul
# Min Z = x+y
# subject to
# x>= =6
# y>= =6
# x+y<=11
# x>=0, y>=0
import pulp
Status: Infeasible
Optimal solution: Z = 12.0
x = 6.0
y = 6.0
8 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [6]: #Q9) Apply Python program in each of the following transformations on the
#(I) Refection through X−axis.
#(II) Scaling in X−coordinate by factor 2.
#(III) Scaling in Y−coordinate by factor 1.5.
#(IV) Reflection through the line y = x.
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def reflect_x_axis(point):
return Point(point.x, -point.y)
def reflect_through_line(point):
return Point(point.y, point.x)
9 of 10 26/03/24, 11:33
PRAJAPATI SANJAY PRACTICAL NO_1 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [7]: #Q10) Find the combined transformation of the line segment between the poi
# 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.
import numpy as np
def reflect_through_line(point):
return np.array([-point[1], -point[0]])
scaled_point_A = scale_x_coordinate(rotated_point_A, 2)
scaled_point_B = scale_x_coordinate(rotated_point_B, 2)
reflected_point_A = reflect_through_line(scaled_point_A)
reflected_point_B = reflect_through_line(scaled_point_B)
sheared_point_A = shear_x_direction(reflected_point_A, 4)
sheared_point_B = shear_x_direction(reflected_point_B, 4)
In [ ]:
10 of 10 26/03/24, 11:33