Slip NO - 3
Slip NO - 3
Slip NO - 3
In [1]: #Q.1)Write a Python program to plot graph of the functions f(x) = cos(x) i
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,2*np.pi)
# Compute y values using the function f(x) = log10(x)
y = np.cos(x)
# Plot the graph
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x) = log10(x)')
plt.title('2D Graph of f(x) = log10(x)')
plt.grid(True)
plt.show()
1 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [2]: #Q.2) Write a Python program to generate 3D plot of the functions z = sin x
y in -10 < x, y < 10.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Generate x, y coordinates
x = np.linspace(-10, 10, 100)
y = np.linspace(-10, 10, 100)
X, Y = np.meshgrid(x, y)
# Compute z values
Z = np.sin(X) + np.cos(Y)
# Create 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the surface
surf = ax.plot_surface(X, Y, Z, cmap='viridis')
# Add labels and title
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('3D Plot of z = sin(x) + cos(y)')
# Show the plot
plt.show()
2 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
3 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [6]: #Q.4) write a Python program to reflect the line segment joining the points
and B[l, 4] through the line y = x + 1.
import numpy as np
# Define the points A and B
A = np.array([5, 3])
B = np.array([1, 4])
# Define the equation of the reflecting line
def reflect(line, point):
m = line[0]
c = line[1]
x, y = point
x_reflect = (2 * m * (y - c) + x * (m ** 2 - 1)) / (m ** 2 + 1)
y_reflect = (2 * m * x + y * (1 - m ** 2) + 2 * c) / (m ** 2 + 1)
return np.array([x_reflect, y_reflect])
# Define the equation of the reflecting line y = x + 1
line = np.array([1, -1])
# Reflect points A and B through the reflecting line
A_reflected = reflect(line, A)
B_reflected = reflect(line, B)
# Print the reflected points
print("Reflected Point A':", A_reflected)
print("Reflected Point B':", B_reflected)
In [7]: # Q5)If the line with points A[2, 1], B[4, -1] is transformed by the transf
matrix [T] = 1 2 then using python, find the equation of transformed
2 1
import numpy as np
# Define original line points
A = np.array([2, 1])
B = np.array([4, -1])
# Define transformation matrix [T]
T = np.array([[1, 2], [2, 1]])
# Find transformed points A' and B'
A_transformed = np.dot(T, A)
B_transformed = np.dot(T, B)
# Extract coordinates of transformed points
x1_transformed, y1_transformed = A_transformed
x2_transformed, y2_transformed = B_transformed
# Find equation of transformed line
m_transformed = (y2_transformed - y1_transformed) / (x2_transformed -
x1_transformed)
b_transformed = y1_transformed - m_transformed * x1_transformed
# Format the equation of the transformed line
equation_transformed = f'y = {m_transformed} * x + {b_transformed}'
print("Equation of transformed line: ", equation_transformed)
4 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [8]: # Q.6) Generate line segment having endpoints (0, 0) and (10, 10) find midp
of line segment.
# Define endpoints
x1, y1 = 0, 0
x2, y2 = 10, 10
# Calculate midpoint
midpoint_x = (x1 + x2) / 2
midpoint_y = (y1 + y2) / 2
# Print midpoint
print("Midpoint: ({}, {})".format(midpoint_x, midpoint_y))
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
'_'")
Optimal solution:
x = 15.0
y = 2.0
Optimal value of Z = 56.5
5 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [14]: #
Optimal solution:
x = 0.0
y = 0.0
z = 0.0
6 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
C:\Users\HP\AppData\Local\Temp\ipykernel_12604\2248711863.py:42: De
precationWarning: `method='simplex'` is deprecated and will be remo
ved in SciPy 1.11.0. Please use one of the HiGHS solvers (e.g. `met
hod='highs'`) in new code.
result = linprog(c, A_ub=A, b_ub=b, bounds=bounds, method='simple
x')
7 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
In [ ]:
8 of 9 26/03/24, 11:37
PRAJAPATI SANJAY PRACTICAL NO_3 - Jupyter Notebook http://localhost:8888/notebooks/PRAJAPATI%20SAN...
9 of 9 26/03/24, 11:37