Practical No 4
Practical No 4
In [2]: #Q1) Write a Python program to plot graph of the functions f(x) = log10(x)
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return np.log10(x)
x = np.linspace(0.1, 10, 100)
y = f(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('Graph of f(x) = log10(x)')
plt.show()
1 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [3]: #Q2)Write a Python program to plot graph of the functions f(x) = sin^-1 (x)
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return np.arcsin(x)
x = np.linspace(-1, 1, 100)
y = f(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.title('Graph of f(x) = sin⁻¹(x)')
plt.show()
2 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [5]: #Q3) Using Python plot the surface plot of parabola z = x**2 + y**2 in -6 <
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def f(x, y):
return 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)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('Surface plot of z = x^2 + y^2')
plt.show()
3 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [17]: #Q4) If the line with points A[3, 1], B[5, -1] is transformed by the transf
matrix [T] = 3 −2
2 1 then using python, find the equation of transformed
import numpy as np
4 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [6]: #Q5)Write a Python program to draw a polygon with vertices (0,0), (2,0), (2
and (1,6) and rotate by 1800
5 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [7]: #Q6)Using python, generate line passing through points (2,3) and (4,3) and
6 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
C:\Users\HP\AppData\Local\Programs\Python\Python310\lib\site-packag
es\pulp\pulp.py:1316: UserWarning: Spaces are not permitted in the
name. Converted to '_'
warnings.warn("Spaces are not permitted in the name. Converted to
'_'")
Status: Optimal
x = 3.00
y = 0.00
Z = 450.00
7 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [14]: #Q8) Write a python program to display the following LPP by using pulp
module and simplex method. Find its optimal solution if exist.
Min Z = 4x+y+3z+5w
subject to
4x+-6y-4w >= -20 -8x-3y+3z+2w <= 20
x + y <= 11
x >= 0,y>= 0,z>= 0,w>= 0
Optimal Solution:
w = 21.75
x = 11.0
y = 0.0
z = 21.5
Optimal Value: 217.25
8 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [15]: #Q9) Plot 3D axes with labels X - axis and z –axis and also plot following
with given coordinate in one graph
(I) (70, -25, 15) as a diamond in black color
(II) (50, 72, -45) as a* in green color,
(III) (58, -82, 65) as a dot in green color,
(IV) (20, 72, -45) as a * in Red color.
9 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [16]: #Q10)Q.10) Find the combined transformation of the line segment between the
A[4, -1] & B[3, 0] by using Python program for the following sequence
transformation:-
(I) Shearing in X – Direction by 9 unit
(II)
(III)
import numpy as np
import matplotlib.pyplot as plt
A = np.array([4, -1])
B = np.array([3, 0])
T1 = np.array([[1/9, 0], [0, 1]])
T2 = np.array([[-1, 0], [0, -1]])
T3 = np.array([[2, 0], [0, 1]])
T4 = np.array([[0, 1], [1, 0]])
AB = B - A
AB_T1 = T1 @ AB
AB_T2 = T2 @ AB_T1
AB_T3 = T3 @ AB_T2
AB_T4 = T4 @ AB_T3
A_T = A + AB_T4
B_T = B + AB_T4
plt.plot([A[0], B[0]], [A[1], B[1]], 'b', label='Original line segment'
plt.plot([A_T[0], B_T[0]], [A_T[1], B_T[1]], 'r', label='Transformed line s
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.show()
10 of 11 26/03/24, 11:41
PRAJAPATI SANJAY PRACTICAL NO_4 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [ ]:
11 of 11 26/03/24, 11:41