Python codes sem 5
Python codes sem 5
SLIP NO :1
1) Write a python program to plot 2D graph of the functions f(x)= x^2 and g(x) in [-1,1].
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
plt.legend()
plt.grid()
plt.show()
2) Write a python program to plot 3D graph of the functions f(x)=e^(-x^2) in [-5,5] with green dashed
points with upward pointing triangle.
Ans:
import numpy as np
x = np.linspace(-5, 5, 100)
z = np.exp(-x**2)
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
plt.show()
Expenditure in Rs=[600,4000,2000,1500,700]
Ans:
plt.xlabel("Items", fontsize=12)
plt.show()
1) Write a python program to reflect the line segment joining the points A[5,3] and B [1,4] through the
line y=x+1.
Ans:
import numpy as np
x_reflected = 2 * d - x
A = (5, 3)
B = (1, 4)
line_slope = 1
line_intercept = 1
2) Write a python program draw polygon with vertices(0,0),(2,0),(2,3) and (1,6) and rotate by 180°.
Ans:
import numpy as np
vertices = np.array([[0, 0], [2, 0], [2, 3], [1, 6], [0, 0]])
rotated = -vertices
plt.plot(vertices[:, 0], vertices[:, 1], 'b-o', label="Original")
plt.legend()
plt.axis('equal')
plt.show()
3) Write a python program to find the area and perimeter of the ΔABC A[0,0],B[5,0],c[3,3].
Ans:
import math
A = (0, 0)
B = (5, 0)
C = (3, 3)
AB = distance(A, B)
BC = distance(B, C)
CA = distance(C, A)
perimeter = AB + BC + CA
s = perimeter / 2
I) Max Z=150x+75y
Subject to 4x + 6y ≤ 24.
5x + 3y ≤ 15.
x ≥ 0,y ≥0.
Ans:
c = [-150, -75]
b = [24, 15]
if result.success:
else:
print("No solution")
Il)Write a python program to display the following LPP using pulp modulo and simplex method . Find the
optimal solution if exits .
Min Z=x + y
Subject to x ≥ 6
Y ≥6
x + y ≤ 11
x ≥0 , y ≥0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Ans:
P = [3, -1]
2) Find the combine transformation of the line segment between the points A[5,-2] & B[4,3] by using
python program for the following sequence of transformation :-
Ans:
def transform(point):
x, y = point
x, y = -x, -y
x, y = 2 * x, y
x, y = -y, -x
x, y = x + 4 * y, y
return [x, y]
A_transformed = transform(A)
B_transformed = transform(B)
SLIP NO:2
Ans:
import numpy as np
y = np.log10(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.grid(True)
plt.show()
2) Using python generate 3D surface plot for the function f(x)= sin(x² + y² ) in the interval [0,10].
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
3) Using python ,draw a bar graph in GREEN to represent the data below:
Ans:
plt.xlabel("Subjects")
plt.ylabel("Percentage")
plt.show()
1) Using sympy declare the points A(0,2), B(5,2),C(3,0) cheak whether these points are collinear .Declare
the line passing through points A & B find the distance of these line from point C.
Ans:
import sympy as sp
A = sp.Point2D(0, 2)
B = sp.Point2D(5, 2)
C = sp.Point2D(3, 0)
are_collinear = sp.Point.is_collinear(A, B, C)
line_AB = sp.Line(A, B)
distance_C_to_AB = line_AB.distance(C)
2) Using python ,draw a regular polygon with 6 sides and radius 1 centered at (1,2) and find its area and
perimeter.
Ans:
import numpy as np
sides = 6
radius = 1
center = (1, 2)
plt.plot(x, y, 'r-')
plt.xlim(0, 3)
plt.ylim(1, 4)
plt.gca().set_aspect('equal')
plt.title(f'Hexagon\nArea: {area:.2f}, Perimeter: {perimeter:.2f}')
plt.grid()
plt.show()
3) Write a python program to find area and perimeter of the ΔABC where A[0,0], B[6,0] and C[4,4].
Ans:
import math
A = (0, 0)
B = (6, 0)
C = (4, 4)
perimeter = AB + BC + CA
Max Z=5x + 3y
Subject to x + y ≤ 7.
2x + 5y ≤ 1.
X ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 5 * x + 3 * y
prob += x + y <= 7
prob += 2 * x + 5 * y <= 1
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
II) Write a python program to display the following LPP using pulp modulo and simplex method .Find its
optimal solution if exits.
Max Z= 3x + 2y + 5z
Subject to x + 2y +z ≤ 430
3x + 2z ≤ 460
x + 4y ≤ 120
x ≥ 0,y ≥ 0,z ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += 3 * x + 2 * y + 5 * z
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
1) Apply python program in each of the following transformations on the points P[4,-2].
Ans:
import numpy as np
P = np.array([4, -2])
Ans:
import numpy as np
A = np.array([4, -1])
B = np.array([3, 0])
A_transformed = T @ A
B_transformed = T @ B
print(f"Transformed A: {A_transformed}")
print(f"Transformed B: {B_transformed}")
SLIP NO: 3
1) Using python plot the graph of function f(x)= cos (x) on the interval [0,2π].
Ans:
import numpy as np
y = np.cos(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.grid(True)
plt.show()
Ans:
plt.xlabel('Games')
plt.ylabel('Number of Students')
plt.grid(True)
plt.show()
3) Write a python program to generate 3D plot of the function z= sin x+ cos x in -10 < x, y < 10.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
1) Write a python program to reflect line segment joining the points A[5,3] and B[1,4] through line
y=x+1.
Ans:
import numpy as np
A = np.array([5, 3])
B = np.array([1, 4])
def reflect_point(point):
x, y = point
x_reflected = (x - y + 2) / 2
y_reflected = (y - x + 2) / 2
A_reflected = reflect_point(A)
B_reflected = reflect_point(B)
print(f"Reflected A: {A_reflected}")
print(f"Reflected B: {B_reflected}")
2) If the line with points A[2,1],B[4,-1] is transformed by the transformation matrix [T]=[ 1 2
Ans:
import numpy as np
A_prime, B_prime = T @ A, T @ B
c = A_prime[1] - m * A_prime[0]
3) Generate the line segment having endpoints (0,0) and (10,10) . Find the mid points of line segment .
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([10, 10])
midpoint = (A + B) / 2
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2) Write a program to display the following LPP using pulp modulo and simplex method . Find its optimal
solution if exits.
2x2 + 5x3 ≤ 10
x1 ≥0, x2 ≥ 0, x3 ≥0
Ans:
import pulp
x1 = pulp.LpVariable('x1', lowBound=0)
x2 = pulp.LpVariable('x2', lowBound=0)
x3 = pulp.LpVariable('x3', lowBound=0)
prob += 3 * x1 + 5 * x2 + 4 * x3
prob += 2 * x1 + 3 * x2 <= 8
prob += 2 * x2 + 5 * x3 <= 10
prob += 3 * x1 + 2 * x2 + 4 * x3 <= 15
prob.solve(pulp.PULP_CBC_CMD(msg=1))
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Ans:
import numpy as np
P = np.array([4, -2])
2) Find the combine transformation ofthe line segment between points A[2,-1] & B[5,4] by using python
program for each following sequence of transformations:-
Ans:
import numpy as np
A_transformed, B_transformed = T @ A, T @ B
SLIP NO =4
Ans:
import numpy as np
y = np.log10(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.grid(True)
plt.show()
2)Using python plot the graph of function f(x)=sin⁻¹ (x) interval [-1,1].
Ans:
import numpy as np
x = np.linspace(-1, 1, 400)
y = np.arcsin(x)
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.grid(True)
plt.show()
3)Using python plot the surface plot of parabola x= x^2 +y^2 in -6< x,y < 6.
Ans:
import numpy as np
x = np.linspace(-6, 6, 400)
y = np.linspace(-6, 6, 400)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
1) If the line with points A[3,1] , B [ 5,-1] is transformed by the transformation matrix [T]=[3 -2
Ans:
import numpy as np
A_prime, B_prime = T @ A, T @ B
c = A_prime[1] - m * A_prime[0]
print(f"A' = {A_prime}, B' = {B_prime}, Line: y = {m:.2f}x + {c:.2f}")
2) Write a python program to draw a polygon with vertices (0,0),(2,0),(2,3) & (1,6 ) and rotate it by 180∘
Ans:
import numpy as np
vertices_rotated = vertices.dot(rotation_matrix)
plt.legend()
plt.show()
3) Using python generate line passing through points (2,3) & (4,3) and find equation of the line.
Ans:
import numpy as np
A = np.array([2, 3])
B = np.array([4, 3])
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Line passing through points (2, 3) and (4, 3)')
plt.grid(True)
plt.show()
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 150 * x + 75 * y
prob += 4 * x + 6 * y <= 24
prob += 5 * x + 3 * y <= 15
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2) Write a python program to display the following LPP by using pulp modulo and simplex method . Find
its optimal solution if exits .
Max Z = 4x + y + 5z + 5w
Subject to 4x + 6y - 5z - 4w ≥ -20
-8x - 3y +3z + 2w ≤ 20
x + y ≤11
x ≥ 0, y ≥ 0, z ≥ 0, w≥ 0
Ans:
prob += x + y <= 11
prob.solve()
print("x=", x.varValue, "y=", y.varValue, "z=", z.varValue, "w=", w.varValue, "Max Z=",
value(prob.objective))
1) Plot 3D axes with label as x-axis and z- axis and also plot following with given coordinates in one
graph.
Ans:
# Coordinates
points = [
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
2) Find the combine transformation of the line segment between the points A[4,-1] &B[3,0] by
using python program for the following sequence of transformation.
Ans:
import numpy as np
print("Transformed A:", A)
print("Transformed B:", B)
PYTHON PROGRAMMING LANGUAGE=II
SLIP NO =5
1) Using python plot the surface plot of function z=cos(x^2-y^2-0.5) in the interval from -1 < x, y
<1.
Ans:
x = np.linspace(-1, 1, 400)
y = np.linspace(-1, 1, 400)
x, y = np.meshgrid(x, y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
2) Generate 3D surface plot for the fuctions f(x)=sin(x^2 + y^2) in the interval [0,10].
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
3) Write a program to generate 3D plot of the fuctions z= sin x + cos y in the interval -10 < x,y < 10.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
1) Using python to generate triangle with vertices(0,0),(4,0),(4,3) cheak wheather triangle is Right angle
triangle
Ans:
import math
Ans:
import numpy as np
x = np.linspace(-7, 7, num=100)
print(x)
3)Write a python program to find the area and perimeter ΔABC where, A[0,0],B[6,0],C[4,4].
Ans:
import math
perimeter = AB + BC + CA
area = 0.5 * abs(A[0] * (B[1] - C[1]) + B[0] * (C[1] - A[1]) + C[0] * (A[1] - B[1]))
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Max Z=5x + 3y
Subject to x + y ≤ 7
2x + 5y ≤ 1
x ≥ 0,y ≥0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 5 * x + 3 * y
prob += x + y <= 7
prob += 2 * x + 5 * y <= 1
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
3) Write a python program to display the following LPP using pulp modulo and simplex method .Find its
optimal solution if exits .
Max Z= 4x + y + 3z +5w
-3x - 2y +4z + w ≤ 10
-8x - 3y + 3z + 2w ≤ 20
x + y ≤ 11
x,y,z,w ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
w = pulp.LpVariable('w', lowBound=0)
prob += 4 * x + y + 3 * z + 5 * w
prob += 4 * x + 6 * y - 5 * z - 4 * w >= 20
prob += -3 * x - 2 * y + 4 * z + w <= 10
prob += -8 * x - 3 * y + 3 * z + 2 * w <= 20
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal w: {pulp.value(w)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
B) Attempt any one of the following.
1) Apply python program in each of the following transformation on the point P[3,8]
Ans:
import numpy as np
P = np.array([3, 8])
P = np.array([P[0], -P[1]])
theta = np.radians(30)
rotation = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P = rotation @ P
P = np.array([-P[1], -P[0]])
print(f"Transformed P: {P}")
2) Write a program to plot 2D X-axis and Y-axis in black colour . In the same direction plot :-
Ans:
fig, ax = plt.subplots()
ax.axhline(0, color='black')
ax.axvline(0, color='black')
ax.set_aspect('equal')
plt.xlim(-1, 12)
plt.ylim(-1, 10)
plt.show()
PYTHON PROGRAMMING LANGUGAE=II
SLIP NO=6
1)Draw the horizontal bar graph for the following datain Martoon colour .
Ans:
plt.ylabel('City')
plt.show()
2)Using python 3D surface plot for the function f(x)=sin(x^2+y^2) in the interval [0,10].
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.xlabel('X')
plt.ylabel('Y')
ax.set_zlabel('f(x, y)')
plt.show()
3) Using python plot the graph of function f(x)= sin x-e^x +3x^2 - log10(x) on the inverval [0,2π].
Ans:
import numpy as np
import math
def f(x):
y = f(x)
plt.plot(x, y, label='f(x) = sin(x) - e^x + 3x^2 - log10(x)')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
1) Using python rotate the line segment by 180° having end points (1,0) and (2,-1).
Ans:
import numpy as np
plt.legend()
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
2)Write a python program to draw a polygon with vertices (0,0),(2,0),(2,3) and (1,6) and rotate it by
180°.
Ans:
import numpy as np
plt.legend()
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
2) Using python generate triangle with vertices (0,0),(4,0),(2,4) cheak wheather thetriangle isoscale
triangle .
Ans:
import numpy as np
A, B, C = np.array([0, 0]), np.array([4, 0]), np.array([2, 4])
isosceles = AB == BC or BC == CA or CA == AB
Maz Z=x + y
Subject to 2x -2y ≥ 1
x + y ≥ 2.
x ≥ 0,y ≥ 0
Ans:
def remove_comments(code):
"""
Args:
Returns:
lines = code.splitlines()
new_lines = []
comment_start = line.find('#')
if comment_start == -1:
new_lines.append(line)
else:
new_lines.append(line[:comment_start].strip())
return '\n'.join(new_lines)
# Example usage:
code_with_comments = """
# This is a comment
x = 5 # Another comment
"""
code_without_comments = remove_comments(code_with_comments)
print(code_without_comments)
2) Write a python program to display the the following LPP using pulp modulo and simplex method
. Find the optimal solution if exits.
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Apply python program in each ofthe following transformation on the point P[ 4,-2]
Ans:
import numpy as np
P = np.array([4, -2])
P = np.array([-P[0], P[1]])
P = np.array([-P[1], -P[0]])
SLIP NO:7
1) Plot the graph of f(x)= x^ 4 in [0,5] with red dashed line with circle markers.
Ans:
import numpy as np
return x**4
x = np.linspace(0, 5, 100)
y = f(x)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
2) Using python generate 3D surface plot for function f(x)=sin(x^2 + y^2) on the interval [0,10].
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.xlabel('X')
plt.ylabel('Y')
ax.set_zlabel('f(x, y)')
plt.show()
3) Write a python program to rectangle with vertices [1,0],[2,1],[1,2] and [0,1] its rotation about oringin
by π/2 radians .
Ans:
return -y, x
vertices.append(vertices[0])
rotated_vertices.append(rotated_vertices[0])
plt.figure(figsize=(8, 8))
plt.legend()
plt.grid(True)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
1) Write a python program to reflecte the line segment joining the points A[5,3] & B[1,4] through
the line y=x+1`
Ans:
d = (x + (y - c) * m) / (1 + m**2)
x_reflect = 2 * d - x
y_reflect = 2 * d * m - y + 2 * c
A = [5, 3]
B = [1, 4]
m, c = 1, 1
2) Using sympy declare the points P(5,2),Q(5,-2),R(5,0),cheak whether these points are
collinear.Declare the ray passing through the points P and Q find the length of the this ray between P
and Q .Also find slop of this ray
Ans:
import sympy as sp
P = sp.Point(5, 2)
Q = sp.Point(5, -2)
R = sp.Point(5, 0)
collinear = sp.Point.is_collinear(P, Q, R)
ray_PQ = sp.Ray(P, Q)
length_PQ = P.distance(Q)
print(f"The slope of the ray between P and Q is: {slope_PQ if slope_PQ is not None else 'undefined
(vertical line)'}")
3)Write a pyhton program in 3D to rotate the point A(1,0,0) through X plane anticlockwise
direction(Rotation through Z axis) by angle of 90°
Ans:
import numpy as np
A = np.array([1, 0, 0])
theta = np.pi / 2
rotation_matrix = np.array([
[0, 0, 1]
])
A_rotated = rotation_matrix @ A
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2)Write a python program to display following LPP using pulp modulo and simplex method. Findt its
optimal solution if exits.
Max Z= x+2y+1z
Subject to x+2y+2z ≤ 1
3x+2y+z ≥8
x ≥ 0,y ≥ 0, z ≥ 0.
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += x + 2*y + z
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Apply python program on each of the following transformation of the point P[4,-2]
I) Refection throughX-axis.
Ans:
import numpy as np
P = np.array([4, -2])
P_reflect_x = np.array([P[0], -P[1]])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate_origin = rotation_matrix @ P
shear_matrix = np.array([
[1, 7/2],
[0, 1]
])
P_shear_x = shear_matrix @ P
2)Find the combine transformation of the line segment between the points A[7,-2] and B[6,2] by using
python program for each following sequence of transformation:-
Ans:
import numpy as np
theta = np.pi / 3
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
scale_x_matrix = np.array([
[7, 0],
[0, 1]
])
uniform_scale_matrix = np.array([
[-4, 0],
[0, -4]
])
reflection_x_matrix = np.array([
[1, 0],
[0, -1]
])
transform = reflection_x_matrix @ uniform_scale_matrix @ scale_x_matrix @ rotation_matrix
A_transformed = transform @ A
B_transformed = transform @ B
SLIP NO:8
1) Plot the graphs of sin x, cos x,e^x, and x^2 in[0,5] in one figure with(2x2) subplots.
Ans:
import numpy as np
x = np.linspace(0, 5, 100)
axs[0, 1].set_title('cos(x)')
axs[1, 0].set_title('e^x')
axs[1, 1].set_title('x^2')
plt.show()
2) Using python plot the graph of function f(x)= cos x with interval [0,2π ].
Ans:
import numpy as np
y = np.cos(x)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
3) Write a python program to generate 3D plot of the functions z= sin x+ cos y in -10<x, y < 10.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
1) Write a python program in 3D to rotate the point (1,0,0) through xz plane in anticlosewise
direction(Rotation through Y-axis) by angle of 90°
Ans:
import numpy as np
A = np.array([1, 0, 0])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), 0, np.sin(theta)],
[0, 1, 0],
[-np.sin(theta), 0, np.cos(theta)]
])
A_rotated = rotation_matrix @ A
2)Using python generate triangle with vertices (0,0),(4,0),(1,4) cheak whether the triangle is Scalene
triangle.
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([4, 0])
C = np.array([1, 4])
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
print(f"The triangle with vertices A{A}, B{B}, and C{C} is a scalene triangle: {is_scalene}")
2) Write a python program to find the area and perimeter of the ΔABC where A[0,0],B[6,0],C[4,4].
Ans:
import numpy as np
perimeter = AB + BC + CA
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 150 * x + 75 * y
prob += 4 * x + 6 * y <= 24
prob += 5 * x + 3 * y <= 15
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
3) Write a program to display the following LPP using pulp modulo and simplex method. Find its
opmtimal solution if exits.
Max Z=3x + 2y + 4z
Subject to 2x + 3y ≤ 8
2x + 5y ≤ 10
3x + 2y 4z ≤ 15
x ≥ 0,y ≥ 0,z ≥ 0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += 3*x + 2*y + 4*z
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Apply python program in each of the following transformation of the point [4-2]
Ans:
import numpy as np
P = np.array([4, -2])
theta = np.pi
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate_origin = rotation_matrix @ P
shear_matrix = np.array([
[1, -2],
[4, 1]
])
P_shear = shear_matrix @ P
2) Find the combine transformation of the line segment between the pointsA[4,-1] and & B[3,2]by
using python program for the following sequence of transformation:-
Ans:
import numpy as np
A = np.array([4, -1])
B = np.array([3, 2])
transform = np.array([
[-5, 20],
[-5, 1]
]) @ np.array([
])
A_transformed = transform @ A
B_transformed = transform @ B
SLIP NO:9
1) Write a python program to plot 2D X-axis and Y-axis black clolour and in the same diagram in plot
green triangle with vertices [5,4[,[7,4],[6,6].
Ans:
fig, ax = plt.subplots()
ax.add_patch(triangle)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.grid(True)
ax.set_aspect('equal', adjustable='box')
plt.show()
2) Write a python program to rotate the point through yz plane in anticlockewise direction(Rotation
through Y-axis) by angle of 90°
Ans:
import numpy as np
P = np.array([0, 1, 0])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), 0, np.sin(theta)],
[0, 1, 0],
[-np.sin(theta), 0, np.cos(theta)]
])
P_rotated = rotation_matrix @ P
3)Using python plot the graph of function f(x)= cos x with interval [0,2π ].
Ans:
import numpy as np
import matplotlib.pyplot as plt
y = np.cos(x)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
1) Write apython program to rotate the rays by 90° having starting point(1,0) and (2,-1).
Ans:
import numpy as np
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P1_rotated = rotation_matrix @ P1
P2_rotated = rotation_matrix @ P2
2)Using sympy declare the points A(0,7),B(5,-2).Declare the line segment passing through them.Find the
length and mid point o fthe line segment passing through points A and B.
Ans:
import sympy as sp
line_segment = sp.Segment(A, B)
length = line_segment.length
midpoint = line_segment.midpoint
2) Write a python program to find the area and perimeter ΔABC where A(0,0),B(5,0),C(3,3).
Ans:
import numpy as np
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
perimeter = AB + BC + CA
area = 0.5 * np.abs(A[0] * (B[1] - C[1]) + B[0] * (C[1] - A[1]) + C[0] * (A[1] - B[1]))
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 150 * x + 75 * y
prob += 4 * x + 6 * y <= 24
prob += 5 * x + 3 * y <= 15
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2)Write a python program to display the following LPP using pulp modulo and simplex method ,Find it's
optimal solution if exits .
Max Z= 4x + y + 3z +5w
-3x - 2y +4z + w ≤ 10
-8x - 3y + 3z + 2w ≤ 20
x + y ≤ 11
x,y,z,w ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
w = pulp.LpVariable('w', lowBound=0)
prob += 4 * x + y + 3 * z + 5 * w
prob += 4 * x + 6 * y - 5 * z - 4 * w >= 20
prob += -3 * x - 2 * y + 4 * z + w <= 10
prob += -8 * x - 3 * y + 3 * z + 2 * w <= 20
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal w: {pulp.value(w)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
1) Write a python program to apply the following transformations on the following point (2,-4) :
Ans:
import numpy as np
P = np.array([2, -4])
theta = np.pi / 3
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate = rotation_matrix @ P
2) Write a python program to find the combined transformation of the line segemnt between the
points A[5,3] and B[1,4] for the following sequence of transformations:
Ans:
import numpy as np
A, B = np.array([5, 3]), np.array([1, 4])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
uniform_scale_matrix = np.array([
[-3.5, 0],
[0, -3.5]
])
scale_y_matrix = np.array([
[1, 0],
[0, 5]
])
shear_matrix = np.array([
[1, 3],
[4, 1]
])
A_transformed = combined_transform @ A
B_transformed = combined_transform @ B
SLIP NO:10
1)Write a python program in 3D to rotate the point (1,0,0) through xz plane in anticlosewise
direction(Rotation through Y-axis) by angle of 90°
Ans:
import numpy as np
A = np.array([1, 0, 0])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), 0, np.sin(theta)],
[0, 1, 0],
[-np.sin(theta), 0, np.cos(theta)]
])
A_rotated = rotation_matrix @ A
Expenditure in Rs=[600,4000,2000,1500,700]
Ans:
plt.xlabel("Items", fontsize=12)
plt.show()
3)Write a python program to plot the 3D line graph whose parametric equation is (cos (2x),sin(2x),x) for
10 ≤ x ≤ 20 (in red colour ) with title to the graph.
Ans:
import numpy as np
X = np.cos(2 * x)
Y = np.sin(2 * x)
Z=x
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(X, Y, Z, color='red')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
Ans:
import numpy as np
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
A_rotated = rotation_matrix @ A
B_rotated = rotation_matrix @ B
C_rotated = rotation_matrix @ C
3) Draw apolygon with vertices (0,0),(2,0),(2,3),(1,6).Write a python program to rotate the python
program by 180°.
Ans:
import numpy as np
theta = np.pi
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
vertices_rotated = np.dot(vertices, rotation_matrix)
plt.legend()
plt.gca().set_aspect('equal', adjustable='box')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Ans:
import numpy as np
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
perimeter = AB + BC + CA
# Calculate the area using the determinant method
area = 0.5 * np.abs(A[0] * (B[1] - C[1]) + B[0] * (C[1] - A[1]) + C[0] * (A[1] - B[1]))
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Max Z=x+y
Subject to x-y ≥ 1
x+y ≥ 2
x ≥ 0,y ≥ 0
Ans:
import numpy as np
x = np.linspace(0, 5, 400)
y1 = x - 1
y2 = 2 - x
plt.figure(figsize=(8, 8))
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()
2)Write a python program to display the following LPP using pulp modulo and simplex method .Find its
optimal solution if exits.
Max Z= 3x + 2y + 5z
Subject to x + 2y +z ≤ 430
3x + 2z ≤ 460
x + 4y ≤ 120
x ≥ 0,y ≥ 0,z ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += 3 * x + 2 * y + 5 * z
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Ans:
import numpy as np
P = np.array([-2, 4])
theta = np.pi / 6
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate = rotation_matrix @ P
2) Write apython program to find the combined transformation between the points for the
following sequence of transformations:
Ans:
import numpy as np
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
uniform_scale_matrix = np.array([
[3.5, 0],
[0, 3.5]
])
scale_matrix = np.array([
[3, 0],
[0, 5]
])
shear_matrix = np.array([
[1, 6],
[0, 1]
])
A_transformed = combined_transform @ A
B_transformed = combined_transform @ B
SLIP NO:11
Q 1)Attempt any two of the following.
1) Write a python program to plot 3Daxes with labels as X-axis,Y-axis and Z-axis and also
plotfollowing point with coordinates in the same graph :(70,-25,15) as adiamond in black colour.
Ans:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
x, y, z = 70, -25, 15
plt.show()
2) Plot the graph of y=e^x in[-5,5] with red dashed points line with upward pointing triangle.
Ans:
import numpy as np
x = np.linspace(-5, 5, 400)
y = np.exp(x)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
3)Using python ,draw a bar graph in GREEN to represent the data below:
Ans:
plt.xlabel("Subjects")
plt.ylabel("Percentage")
plt.show()
1) Write a python program to reflect the ΔABC through the line y=3 where A(1,0),B(2,-1),C(-1,3).
Ans:import numpy as np
A, B, C = np.array([1, 0]), np.array([2, -1]), np.array([-1, 3])
Ans:
import numpy as np
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
A_rotated = rotation_matrix @ A
B_rotated = rotation_matrix @ B
C_rotated = rotation_matrix @ C
3) Write a python program to draw a polygon with 6 side and radius 1 centered at(1,2) find and its
area and perimeter .
Ans:
import numpy as np
center = [1, 2]
radius = 1
plt.gca().set_aspect('equal', adjustable='box')
plt.title('Hexagon')
plt.show()
perimeter = 6 * radius
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
1)Write a python program to display the the following LPP using pulp modulo and simplex method . Find
the optimal solution if exits.
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
2)Write a program to display the following LPP using pulp modulo and simplex method. Find its
opmtimal solution if exits.
Max Z=3x + 2y + 4z
Subject to 2x + 3y ≤ 8
2x + 5y ≤ 10
3x + 2y 4z ≤ 15
x ≥ 0,y ≥ 0,z ≥ 0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
print(f"Status: {pulp.LpStatus[prob.status]}")
Ans:
import numpy as np
P = np.array([2, -4])
theta = np.pi / 4
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate = rotation_matrix @ P
print(f"Original point: {P}")
2) Write a python to find the combined transformation of the line segment between the points
A[3,2] and B[2,-3] for the following sequence of transformation:
Ans:
import numpy as np
theta = np.pi / 6
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
scale_y_matrix = np.array([
[1, 0],
[0, -4]
])
uniform_scale_matrix = np.array([
[-6.4, 0],
[0, -6.4]
])
shear_y_matrix = np.array([
[1, 0],
[5, 1]
])
A_transformed = combined_transform @ A
B_transformed = combined_transform @ B
SLIP NO: 12
Q 1) Attempt any two of the following.
1) Write a python program to plot the graph of y= x^3 +10x-5, for x∈[-10,10] in red colour .
Ans:
import numpy as np
y = x**3 + 10*x - 5
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()
2)Write a python program in 3D to rotate the point (1,0,0) through xz plane in anticlosewise
direction(Rotation through Y-axis) by angle of 90°
Ans:
import numpy as np
A = np.array([1, 0, 0])
theta = np.pi / 2
rotation_matrix = np.array([
[np.cos(theta), 0, np.sin(theta)],
[0, 1, 0],
[-np.sin(theta), 0, np.cos(theta)]
])
A_rotated = rotation_matrix @ A
3)Using python plot the graph of function f(x)=x^2 on the interval [2,-2].
Ans:
import numpy as np
y = x**2
plt.title('Graph of $f(x)=x^2$')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
Q 2)Attempt any two of the following.
1) Write a python program to rotate the segment by 180° having end points(1,0) and(2,-1).
Ans:
import numpy as np
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
A_rotated = rotation_matrix @ A
B_rotated = rotation_matrix @ B
2)Write a python program to draw polygon with 8 sides having radius 5 centered and origin and findits
area and perimeter.
Ans:
import numpy as np
sides, radius = 8, 5
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
2) Write apython program to find area and perimeter of ΔXYZ where X(1,2),Y(2,-2),Z(-1,2)
Ans:
import numpy as np
a = np.linalg.norm(Y - Z)
b = np.linalg.norm(X - Z)
c = np.linalg.norm(X - Y)
perimeter = a + b + c
s = perimeter / 2
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2)Write a program to display the following LPP using pulp modulo and simplex method. Find its
opmtimal solution if exits.
Max Z=3x + 2y + 4z
Subject to 2x + 3y ≤ 8
2x + 5y ≤ 10
3x + 2y 4z ≤ 15
x ≥ 0,y ≥ 0,z ≥ 0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
Ans:
x, y = -2, 4
x_reflected = -x
y_reflected = -y
x_scaled_7_2 = x_sheared * (7 / 2)
y_scaled_7_2 = y_reflected * (7 / 2)
3) Write a python program to findthe combined transformation of the line between the A[4,1] &
B[-3,0] for the following sequence to transformations:
Ans:
import numpy as np
theta = np.pi / 4
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
uniform_scale_matrix = np.array([
[7.3, 0],
[0, 7.3]
])
scale_x_matrix = np.array([
[3, 0],
[0, 1]
])
shear_matrix = np.array([
[1, 0.5],
[0, 1]
])
A_transformed = combined_transform @ A
B_transformed = combined_transform @ B
SLIP NO: 13
1)Write a python program to plot 2D graph of the functions f(x)= x^2 and g(x) in [-1,1].
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
plt.legend()
plt.grid()
plt.show()
2) Using python plot the surface plot the parabola z= x^2+y^2 in -6<x,y<6.
Ans:
import numpy as np
x = np.linspace(-6, 6, 400)
y = np.linspace(-6, 6, 400)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
3)Write a python program to plot the 3D line graph whose parametric equation is (cos (2x),sin(2x),x) for
10 ≤ x ≤ 20 (in red colour ) with title to the graph.
Ans:
import numpy as np
X = np.cos(2 * x)
Y = np.sin(2 * x)
Z=x
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(X, Y, Z, color='red')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
1)Write a python program to reflect the ΔABC through the line y=3 where A(1,0),B(2,-1),C(-1,3).
Ans:import numpy as np
Ans:
import numpy as np
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
perimeter = AB + BC + CA
area = 0.5 * np.abs(A[0] * (B[1] - C[1]) + B[0] * (C[1] - A[1]) + C[0] * (A[1] - B[1]))
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
3) Using sympy declare the points P(5,2),(5,-2),R(5,0) cheak whether these points are
collinear.Declare the ray passing through the points and P and Q. find the length of this ray between P
and Q .Also find slop of this ray .
Ans:
import sympy as sp
P = sp.Point(5, 2)
Q = sp.Point(5, -2)
R = sp.Point(5, 0)
collinear = sp.Point.is_collinear(P, Q, R)
ray = sp.Ray(P, Q)
length_PQ = P.distance(Q)
Max Z=5x + 3y
Subject to x + y ≤ 7
2x + 5y ≤ 1
x ≥ 0,y ≥0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 5 * x + 3 * y
prob += x + y <= 7
prob += 2 * x + 5 * y <= 1
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
2)Write a python program to display the following LPP using pulp modulo and simplex method .Find its
optimal solution if exits.
Max Z= 3x + 2y + 5z
Subject to x + 2y +z ≤ 430
3x + 2z ≤ 460
x + 4y ≤ 120
x ≥ 0,y ≥ 0,z ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += 3 * x + 2 * y + 5 * z
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Ans:
import numpy as np
P = np.array([-2, 4])
2) Write a python program to find the combined transformation on the line segment between the
points A[4,1] & B[-3,0] for the following sequence of transformation.
Ans:
import numpy as np
theta = np.pi / 4
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
uniform_scale_matrix = np.array([
[7.09, 0],
[0, 7.09]
])
scale_matrix = np.array([
[3, 0],
[0, 3]
])
shear_matrix = np.array([
[1, 0.5],
[0, 1]
])
A_transformed = combined_transform @ A
B_transformed = combined_transform @ B
SLIP NO:14
Q 1)Attempt any two of the following.
1)Write a python program to plot 2D graph of the functions f(x)= x^2 and g(x) in [-1,1].
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
plt.legend()
plt.grid()
4) Write a python program to plot 3D graph of the functions f(x)= e^(-x^2) in [-5,5] with green dashed
points line the upward pointing triangle.
Ans:
import numpy as np
x = np.linspace(-5, 5, 400)
y = np.exp(-x**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, 'g^--')
ax.set_title('3D graph of $f(x) = e^{-x^2}$')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
4) Write a python program to generate 3D plot of the functions z= sin x+ cos y in -5<x, y < 5.
Ans:
import numpy as np
x = np.linspace(-5, 5, 400)
y = np.linspace(-5, 5, 400)
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
1) Write a python program to reflect the line segment joining the points A[5,3] and B[1,4] through the
line y=x+1.
Ans:
import numpy as np
x, y = point
d = (x + (y - c) / b - a / b * y) / (1 + a / b * a / b)
x_reflected = 2 * d - x
y_reflected = a / b * x_reflected - c / b
2)Write a python program to draw polygon with vertices(0,0),(2,0),(2,3) and (1,6) and rotate it by 180°.
Ans:
import numpy as np
v = np.array([[0, 0], [2, 0], [2, 3], [1, 6], [0, 0]])
plt.gca().set_aspect('equal')
plt.legend()
plt.show()
3)Write a python program to find the area and perimeter of the triangle ABC where A[0,0],B[5,0] and
C[3,3].
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([5, 0])
C = np.array([3, 3])
a = np.linalg.norm(B - C)
b = np.linalg.norm(A - C)
c = np.linalg.norm(A - B)
perimeter = a + b + c
area = 0.5 * abs(A[0]*(B[1] - C[1]) + B[0]*(C[1] - A[1]) + C[0]*(A[1] - B[1]))
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 150 * x + 75 * y
prob += 4 * x + 6 * y <= 24
prob += 5 * x + 3 * y <= 15
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
Ans:
import numpy as np
P = np.array([2, -4])
theta = np.pi / 4
rotation_matrix = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
P_rotate = rotation_matrix @ P
2)Write a program to plot 2D X-axis and Y-axis in black colour . In the same direction plot :-
Ans:
fig, ax = plt.subplots()
ax.axhline(0, color='black')
ax.axvline(0, color='black')
plt.xlim(-1, 12)
plt.ylim(-1, 10)
plt.show()
SLIP NO:15
1)Write a python program to find the area and perimeter of the triangle ABC where A[0,0],B[5,0] and
C[3,3].
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([5, 0])
C = np.array([3, 3])
a = np.linalg.norm(B - C)
b = np.linalg.norm(A - C)
c = np.linalg.norm(A - B)
perimeter = a + b + c
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
3) Write a python program to plot the graph of the function ,using def()
3x +9 if 5 ≤ x < 10
Ans:
import numpy as np
def f(x):
if -10 < x < 5:
return x**2 + 4
return 3 * x + 9
x1 = np.linspace(-10, 5, 500)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
3)Plot the graphs of sin x, cos x,e^x, and x^2 in[0,5] in one figure with(2x2) subplots.
Ans:
import numpy as np
x = np.linspace(0, 5, 100)
fig, axs = plt.subplots(2, 2)
axs[0, 0].set_title('sin(x)')
axs[0, 1].set_title('cos(x)')
axs[1, 0].set_title('e^x')
axs[1, 1].set_title('x^2')
plt.show()
3)Plot the graphs of sin x, cos x,e^x, and x^2 in[0,5] in one figure with(2x2) subplots.
Ans:
import numpy as np
x = np.linspace(0, 5, 100)
axs[0, 0].set_title('sin(x)')
axs[0, 1].set_title('cos(x)')
axs[1, 0].set_title('e^x')
axs[1, 1].set_title('x^2')
plt.show()
1)Write a python program to rotate the triangle ABC through the line by 180°where A[1,2],B[2,-2],C[-
1,2].
Ans:
import numpy as np
A = np.array([1, 2])
B = np.array([2, -2])
C = np.array([-1, 2])
plt.legend()
plt.show()
2)Write a python program to plot the graph of the function f(x)=e^x in the interval [-10,10].
Ans:
import numpy as np
y = np.exp(x)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
3)Write a python program to plot the 3D line graph whose parametric equation is (cos (2x),sin(2x),x) for
10 ≤ x ≤ 20 (in red colour ) with title to the graph.
Ans:
import numpy as np
Y = np.sin(2 * x)
Z=x
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(X, Y, Z, color='red')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
Ans:
import pulp
prob = pulp.LpProblem("Minimize_Z", pulp.LpMinimize)
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Write a python program to find the combined transformation of the line segment between the
pointsA[5,3],B[1,4] for the following sequence of transformations:
Ans:
import numpy as np
theta = np.pi / 2
2) Write a python program to apply each of the following transformations on the points P[-2,4].
Ans:
import numpy as np
P = np.array([-2, 4])
P_reflected = reflect(P)
P_sheared = shear_x(P_scaled, 2)
SLIP NO :16
1) Using python plot the surface plot the graph of the function z= -x^2-y^2 in -10<x,y<10.
Ans:
import numpy as np
z = -x**2 - y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
2)Write a python program to plot of the function f(x)= log(3x^2),interval [1,10] with the black dashed
points.
Ans:
import numpy as np
y = np.log(3 * x**2)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.grid(True)
plt.show()
2) Write apython program to generate plot of the function f(x)=x^2 , in the interval [-5,5] in figure
of size 6x6 inches.
Ans:
import numpy as np
x = np.linspace(-5, 5, 400)
y = x**2
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
1)Write a python program to declare the line segment passing through the points A(0,7), B(5,2).Also
find the lengh and mid point of the segment passing through points A and B.
Ans:
import numpy as np
A = np.array([0, 7])
B = np.array([5, 2])
length = np.linalg.norm(B - A)
midpoint = (A + B) / 2
print(f"Point A: {A}")
print(f"Point B: {B}")
3) Write a python program to draw polygon with vertices(0,0),(2,0),(2,3) and (1,6) and rotate it by
90°.
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
3)Write a python program to generate vector x in the interval [0,15] using numpy package with 100 sub
intevals .
Ans:
import numpy as np
print(x)
Max Z=5x + 3y
Subject to 3x + 5y ≤ 15
6x + 2y ≤ 24
x ≥ 0,y ≥0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 5 * x + 3 * y
prob += 3 * x + 5 * y <= 15
prob += 6 * x + 2 * y <= 24
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
1) Write apython program to plot the triangle with vertices [4,3],[6,3],[6,5] and its reflection
through 1)x-axis ,2)y-axis .All figures must be different colour also plot the two axes.
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
2)Write apython program to plot the triangle with vertices [3,3],[3,6],[0,6] and its reflection through line
y=x and y-axis .All plot mirror lines.
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
PYHTON PROGRAMMING LANGUAGE=II
SLIP NO:17
1) Write the python program to plot the 3D graph of the function z=x^2+y^2 in -6<x,y<6 unsing
surface plot .
Ans:
import numpy as np
z = x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
2) Write a python program to plot 3D counter for the function f(x,y) log(x^2 y^2) when -5 ≤ x,y ≤ 5
with green colour map.
Ans:
import numpy as np
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, y)
z = np.log(x**2 * y**2)
plt.contourf(x, y, z, cmap='Greens')
plt.colorbar(label='$\log(x^2 y^2)$')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
3) Write a python program to reflect the line segment joining the points A[-5,2] and B[1,4] through the
line y=x.
Ans:
import numpy as np
plt.legend()
plt.show()
1)Write a python program to rotate the line segment by 180° having end points(1,0) and (2,-1).
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2)Write a python program to plot triangle with vertices[3,3][5,6],[5,2] and its rotation about the origin
by angle -π radian .
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
3) Write a python program to draw a polygon with vertices (0,0),(1,0),(2,2)(1,4) and find its area
and perimeter
Ans:
import numpy as np
v = np.array([[0, 0], [1, 0], [2, 2], [1, 4], [0, 0]])
area = 0.5 * np.abs(np.dot(v[:-1, 0], v[1:, 1]) - np.dot(v[:-1, 1], v[1:, 0]))
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
Max Z= 4x + y + 3z +5w
-3x - 2y +4z + w ≤ 20
-8x - 3y + 3z + 2w ≤ 20
x,y, ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z')
w = pulp.LpVariable('w')
prob += 4 * x + 1 * y + 3 * z + 5 * w
prob += -3 * x - 2 * y + 4 * z + 1 * w <= 20
prob += -8 * x - 3 * y + 3 * z + 2 * w <= 20
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
MaxZ= x + y
Subject to x≤ 6
y≤ 6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x <= 6
prob += y <= 6
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Shearing X: {shear_x}")
print(f"Shearing Y: {shear_y}")
2)Write a python program to draw polygon with vertices [3,3],[4,6],[5,4],[4,2] and [2,2] and its
translation in x and y direction by factor -2 and 1 respectively.
Ans:
import numpy as np
v = np.array([[3, 3], [4, 6], [5, 4], [4, 2], [2, 2], [3, 3]])
t = np.array([-2, 1])
v_translated = v + t
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
PYTHON PROGRAMMING LANGUAGE=II
SLIP NO :18
1) Write a python program to draw polygon with vertices[3,3],[4,6],[2,5],[2,2] and its translation in
x and y directions using the fators 3,5 respecively.
Ans:
import numpy as np
v = np.array([[3, 3], [4, 6], [2, 5], [2, 2], [3, 3]])
t = np.array([3, 5])
v_translated = v + t
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2) Write a python program to plot the graph 2x^2-4x+5 in [-10,10] magenta coloured dashed
pattern.
Ans:
import numpy as np
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
3) Write a python program to generate 3D plot of the functions z=x^2 +y^2 in -5<x,y<5.
Ans:
import numpy as np
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
Q 2)Attempt any two of the following.
1) Write a python program to generate vector x in the interval [-22,22] using numpy package with
80 subintervals.
Ans:
import numpy as np
print(x)
2)Write a python program to rotate triange ABC by 90° where A[1,2],B[2,2] and C[-1,2].
Ans:
import numpy as np
v_rotated = v @ rotation
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2) Write a python program to plot rectangle with vertices at[2,1],[2,4],[5,4],[5,1] and its uniform
expansion by factor 4.
Ans:
import numpy as np
v = np.array([[2, 1], [2, 4], [5, 4], [5, 1], [2, 1]])
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
Max Z=2x+3y
Subject to 5x-y ≥ 0
x+y≥6
x ≥ 0,y ≥ 0
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
prob += 2 * x + 3 * y
prob += 5 * x - y >= 0
prob += x + y >= 6
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Write a python program to find the combined transformation of the line segment betweeen the
points A[3,2] and B[2,-3] for the following sequence of transformations:
Ans:
import numpy as np
A = np.array([3, 2])
B = np.array([2, -3])
[np.sin(np.pi/6), np.cos(np.pi/6)]])
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
Ans:
import numpy as np
P = np.array([3, -1])
[np.sin(np.radians(60)), np.cos(np.radians(60))]]
SLIP NO:19
1)Write a python program to plot the graphs of sin x, cos x,e^x, and x^2 in[0,5] in one figure with(2x2)
subplots.
Ans:
import numpy as np
x = np.linspace(0, 5, 100)
axs[0, 0].set_title('sin(x)')
axs[0, 1].set_title('cos(x)')
axs[1, 0].set_title('e^x')
axs[1, 1].set_title('x^2')
plt.show()
2) Write a python program to plot 3D surface plot of the function z=cos( ∣x∣+∣y∣) in -1 < x, y< 1.
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
y = np.linspace(-1, 1, 100)
x, y = np.meshgrid(x, y)
z = np.cos(np.abs(x) + np.abs(y))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
3) Write a python program to plot 2D graph of the functions f(x)=log (x) + 5 and g(x)=log(x)-5 in
[0,10] by setting different line width and different colour to the curve.
Ans:
import numpy as np
f_x = np.log(x) + 5
g_x = np.log(x) - 5
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
1)Write a python program to rotate the ray by 90° in clockwise direction having staring point (0,0) and
end point (4,4).
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2)Write a python program to reflect the triangle ABC through line y=3 where A[1,0],B[2,-1] and C[-1,3].
Ans:
import numpy as np
reflect_y = 3
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
3)Write a python program to draw a polygon with vertices (0,0),(1,0),(2,2)(1,4) and find its area and
perimeter
Ans:
import numpy as np
v = np.array([[0, 0], [1, 0], [2, 2], [1, 4], [0, 0]])
area = 0.5 * np.abs(np.dot(v[:-1, 0], v[1:, 1]) - np.dot(v[:-1, 1], v[1:, 0]))
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
Max Z=3x + 2y + 4z
Subject to 2x + 3y ≤ 8
2x + 5y ≤ 10
3x + 2y +4z ≤ 15
x ≥ 0,y ≥ 0,z ≥ 0.
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob += 3*x + 2*y + 4*z
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
Min Z= x+2y+z
3/2 x+ 2y +z ≥ 8
x ≥ 0, y ≥ 0
Ans:
import pulp
prob += x + 2*y + z
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
1)Write a python program to apply each of the following transformation on the points P=[-2,4].
Ans:
import numpy as np
P = np.array([-2, 4])
[np.sin(np.radians(48)), np.cos(np.radians(48))]]
print(f"Shearing X by 7: {shearing}")
1) Find the combined transformation of the line segment between the points A[4,-1] and B[3,0] for
the following sequence of transformation :
First rotation about origin through an angle π ^ c ; followed by scaling in x coordinate by 3 units ;
followed by reflection through the line y=x.
Ans:
import numpy as np
[np.sin(np.pi), np.cos(np.pi)]])
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
PYTHON PROGRAMMING LANGUAGE=II
SLIP NO:20
1) Write a python program to 2D graph of the function f(x)=sin x and g(x)=cos x in [-2π ,2π ].
Ans:
import numpy as np
f_x = np.sin(x)
g_x = np.cos(x)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
2) Write a python program to plot 2D graph of the function f(x)= e^x sin x in [-5π ,5π] with blue
points line with upward pointing triangle.
Ans:
import numpy as np
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
3)Write a python program to plot the 3D graph of the function f(x)= sin(x² + y² ) -6 < x,y< 6.
Ans:
import numpy as np
x = np.linspace(-6, 6, 100)
y = np.linspace(-6, 6, 100)
x, y = np.meshgrid(x, y)
z = np.sin(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
1)Write apython program to reflect the line segment joining the points A[-5,2],B[3,-4] through the line
y= 2x-1
Ans:
import numpy as np
line_slope, line_intercept = 2, -1
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2)Write apython program to find the area and perimeter of a polygon with vertices (0,0),(-2,0),(5,5)(1,-
1).
Ans:
import numpy as np
vertices = np.array([[0, 0], [-2, 0], [5, 5], [1, -1], [0, 0]])
def polygon_area(verts):
x = verts[:, 0]
y = verts[:, 1]
def polygon_perimeter(verts):
area = polygon_area(vertices)
perimeter = polygon_perimeter(vertices)
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
3)Write a python program to plot the 3D graph of the function f(x,y)=sin x +cos y y,x ∈[-2π ,2π ]using
wireframe plot.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(x, y, z, color='b')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
Max Z=x+y
Subject to x-y ≥ 1
x+y ≥ 2
x ≥ 0,y ≥ 0
Ans:
import numpy as np
x = np.linspace(0, 5, 400)
y1 = x - 1
y2 = 2 - x
plt.figure(figsize=(8, 8))
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Ans:
import numpy as np
P = np.array([3, -2])
P_scaled = P @ scaling_matrix
theta = np.radians(45)
[np.sin(theta), np.cos(theta)]])
Ans:
import numpy as np
P = np.array([3, -2])
P_sheared = P @ shear_matrix
SLIP NO: 21
1) Write a python program to plot 2D graph of the function f(x)=x^4 in [0,5] with red dashed line
with circle markers.
Ans:
import numpy as np
x = np.linspace(0, 5, 100)
f_x = x**4
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
2)Write the python program to plot the 3D graph of the function z=x^2+y^2 in -6<x,y<6 .
Ans:
import numpy as np
y = np.linspace(-6, 6, 100)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
2) Write a python program to plot the 3D graph of the function f(x)=e^{x^2+y^2} for x,y ∈[0,2π]
using wireframe.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.exp(x**2 + y**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(x, y, z, color='b')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
1) If the line segment joining the points A[2,5] and B[4,-13] is transformed to the line segment A’ B’
,by the transformation matrix [T]=[ 2 3
1 4] then using python find the slop and mid point of the
transformed line .
Ans:
import numpy as np
A = np.array([2, 5])
B = np.array([4, -13])
A_transformed = A @ T
B_transformed = B @ T
slope = (B_transformed[1] - A_transformed[1]) / (B_transformed[0] - A_transformed[0])
2) Write a python program to plot square with vertices at [4,4],[2,4],[2,2],[4,2] and find its uniform
expansion by factor 3 ,uniform reduction by factor 0.4
Ans:
import numpy as np
vertices = np.array([[4, 4], [2, 4], [2, 2], [4, 2], [4, 4]])
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.gca().set_aspect('equal', adjustable='box')
plt.grid(True)
plt.show()
3)Write a python program to find the equation of the transformed line if shearing is applied on the line
2x+y=3 in x and y direction by 2 and -3 units respectively.
Ans:
import numpy as np
a, b, c = 2, 1, 3
Min Z= 4x+2y
Subject to x+y ≤ 3
x-y ≤ 2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
lp_problem += 4 * x + 2 * y, "Z"
lp_problem += x + y <= 3
lp_problem += x - y <= 2
lp_problem.solve()
x_value = pulp.value(x)
y_value = pulp.value(y)
z_value = pulp.value(lp_problem.objective)
2x+y ≤ 18
x+2y≥ 30
x≥ 0,y≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
lp_problem += 2 * x + 4 * y, "Z"
lp_problem += 2 * x + y <= 18
lp_problem += x + 2 * y >= 30
lp_problem.solve()
x_value = pulp.value(x)
y_value = pulp.value(y)
z_value = pulp.value(lp_problem.objective)
Ans:
import numpy as np
a, b, c = line
x, y = point
d = (a * x + b * y + c) / (a**2 + b**2)
x_reflect = x - 2 * a * d
y_reflect = y - 2 * b * d
P = np.array([-2, 4])
Ans:
import numpy as np
P = np.array([-2, 4])
P_sheared = P @ shear_matrix
theta = np.radians(48)
[np.sin(theta), np.cos(theta)]])
SLIP NO: 22
1) Write a python progrma to draw 2D plot y= log(x^2)+sin(x) with suitable lable in the x axis and y
axis and a title in [-5π ,5π ]
Ans:
import numpy as np
y = np.log(x**2) + np.sin(x)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
2)Write the python program to plot the 3D dimentional contour plot of parabola z=x^2+y^2 in -
6<x,y<6 .
Ans:
import numpy as np
x = np.linspace(-6, 6, 100)
y = np.linspace(-6, 6, 100)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.colorbar()
plt.show()
2) Write a python program to draw 2D plot y =x sin(1/2) in[-5,5] with suitable label in the x axis ,y
axis a title and location of legend to lower right corner .
Ans:
import numpy as np
x = np.linspace(-5, 5, 500)
y = x * np.sin(0.5 * x)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend(loc='lower right')
plt.grid(True)
plt.show()
1) Write a python program to find the angle at each vertices of the triangle ABC where
A[0,0],B[2,2] & C[0,2].
Ans:
import numpy as np
ab = b - a
ac = c - a
angle = np.arccos(cosine_angle)
return np.degrees(angle)
A = np.array([0, 0])
B = np.array([2, 2])
C = np.array([0, 2])
angle_A = calculate_angle(B, A, C)
angle_B = calculate_angle(A, B, C)
angle_C = calculate_angle(A, C, B)
2) Write a python program to reflect the points P[3,6] through the line x-2y+4=0
Ans:
import numpy as np
a, b, c = line
x, y = point
d = (a * x + b * y + c) / (a**2 + b**2)
x_reflect = x - 2 * a * d
y_reflect = y - 2 * b * d
P = np.array([3, 6])
3)Write a python program to find the area and perimeter of the triangle ABC where A[0,0],B[5,0] and
C[3,3].
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([5, 0])
C = np.array([3, 3])
a = np.linalg.norm(B - C)
b = np.linalg.norm(A - C)
c = np.linalg.norm(A - B)
perimeter = a + b + c
print(f"Perimeter: {perimeter}")
print(f"Area: {area}")
Max Z= 4x + y + 3z +5w
-3x - 2y +4z + w ≤ 10
-8x - 3y + 3z + 2w ≤ 20
x + y ≤ 11
x,y,z,w ≥ 0
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
w = pulp.LpVariable('w', lowBound=0)
prob += 4 * x + y + 3 * z + 5 * w
prob += 4 * x + 6 * y - 5 * z - 4 * w >= 20
prob += -3 * x - 2 * y + 4 * z + w <= 10
prob += -8 * x - 3 * y + 3 * z + 2 * w <= 20
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal w: {pulp.value(w)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
II) Find the distance between two points (0,0) and (1,0)
III) Find the shearing of point (3,4) and X direction by 3 units
Ans:
import numpy as np
print(f"Distance: {distance}")
print(f"Point: {two_d_point}")
2) A company has 3 production facilites S1,S2 and S3 with production capacity of 7,9 and 18 units
( in 100’s )per week of product ,respectively .These unit are to be shipped to 4 respectively.The
transportation cost (in rupees) per unit between factories to warehouse are given in table below .
Write a python to solve the transportation problem for minimize the costs of whole operation
D1 D2 D3 D4 Supply
S1 19 30 50 10 7
S2 70 30 40 60 9
S3 40 8 70 20 18
Demand 5 8 7 14 34
Ans:
import pulp
supply = [7, 9, 18]
for i in range(3):
for j in range(4):
prob.solve()
print("Optimal Solution:")
for i in range(3):
for j in range(4):
SLIP NO:23
1)Write a python program to plot graphs of sin x and cos x in [0,π] in one figure with2×1 subplots.
Ans:
import numpy as np
sin_x = np.sin(x)
cos_x = np.cos(x)
ax1.set_ylabel('sin(x)')
ax1.legend()
ax1.grid(True)
ax2.set_xlabel('X-axis')
ax2.set_ylabel('cos(x)')
ax2.legend()
ax2.grid(True)
fig.suptitle('Graphs of $\sin(x)$ and $\cos(x)$ in [0, π]')
plt.show()
1) Write a python program to plot the graph of the following function in the given intervals :
I) f(x)=x^3 in [0,5]
Ans:
import numpy as np
x1 = np.linspace(0, 5, 100)
x2 = np.linspace(-2, 2, 100)
ax1.plot(x1, x1**3)
ax2.plot(x2, x2**2)
plt.show()
3)Write a python program to plot 3D surface plot of the function z=cos( ∣x∣+∣y∣) in -1 < x, y< 1.
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
y = np.linspace(-1, 1, 100)
x, y = np.meshgrid(x, y)
z = np.cos(np.abs(x) + np.abs(y))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
1) Write a python program to draw regular polygon with 20 sides and radius 1 centered at (0,0).
Ans:
import numpy as np
num_sides = 20
radius = 1
x = radius * np.cos(angles)
y = radius * np.sin(angles)
plt.figure(figsize=(6, 6))
plt.plot(x, y)
plt.gca().set_aspect('equal')
plt.show()
2)Write a python program to draw a polygon with vertices (0,0),(1,0),(2,2)(1,4) and find its area and
perimeter
Ans:
import numpy as np
v = np.array([[0, 0], [1, 0], [2, 2], [1, 4], [0, 0]])
area = 0.5 * np.abs(np.dot(v[:-1, 0], v[1:, 1]) - np.dot(v[:-1, 1], v[1:, 0]))
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
2) Write a python program to find the area and perimeter of the triangle ABC where A[0,0],B[-5,0]
and C[-3,3].
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([-5, 0])
C = np.array([-3, 3])
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
perimeter = AB + BC + CA
s = perimeter / 2
Max Z=3x + 2y + 4z
Subject to 2x + 3y ≤ 8
2x + 5y ≤ 10
3x + 2y 4z ≤ 15
x ≥ 0,y ≥ 0,z ≥ 0.
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
Max Z=3x + 2y + 4z
Subject to 2x + 2y ≤ 12
2x + 2y ≤ 10
5x+3y≤ 15
x ≥ 0,y ≥ 0,
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
lp_problem += 3 * x + 2 * y + 4 * z, "Z"
lp_problem += 2 * x + 2 * y <= 12
lp_problem += 2 * x + 2 * y <= 10
lp_problem += 5 * x + 3 * y <= 15
lp_problem.solve()
x_value = pulp.value(x)
y_value = pulp.value(y)
z_value = pulp.value(z)
z_max_value = pulp.value(lp_problem.objective)
1)Write a python program to apply each of the following transformation on the point[3,-1]
Ans:
import numpy as np
P = np.array([3, -1])
P_reflected = reflection_matrix @ P
theta = np.radians(30)
[np.sin(theta), np.cos(theta)]])
Ans:
import numpy as np
P = np.array([-2, 4])
x, y = point
d = (x + (y - c) * m) / (1 + m**2)
x_reflect = 2*d - x
P_reflected = reflect_point(P, 1, 2)
theta = np.radians(30)
[np.sin(theta), np.cos(theta)]])
SLIP NO:24
1)Write a python program to plot 3D graph of the functions f(x)= e^(-x^2) in [-5,5] with green dashed
points line the upward pointing triangle.
Ans:
import numpy as np
x = np.linspace(-5, 5, 400)
y = np.exp(-x**2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, 'g^--')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
2)Write a python program to plot the graph of the function ,using def()
3x +9 if 5 ≤ x < 10
}
Ans:
import numpy as np
def f(x):
return x**2 + 4
return 3 * x + 9
x1 = np.linspace(-10, 5, 500)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend()
plt.grid(True)
plt.show()
3) Write a python program to plot graphof function f(x)=log(3x^2) in [1,10] with black dashed
points.
Ans:
import numpy as np
y = np.log(3 * x**2)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
1)Write a python program to plot triangle with vertices[3,3][5,6],[5,2] and its rotation about the origin
by angle -π radian .
Ans:
import numpy as np
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
2)Write a python program to generate vector x in the interval [-22,22] using numpy package with 80
subintervals.
Ans:
import numpy as np
print(x)
3)Write a python program to draw a polygon with vertices (0,0),(1,0),(2,2)(1,4) and find its area and
perimeter
Ans:
import numpy as np
v = np.array([[0, 0], [1, 0], [2, 2], [1, 4], [0, 0]])
area = 0.5 * np.abs(np.dot(v[:-1, 0], v[1:, 1]) - np.dot(v[:-1, 1], v[1:, 0]))
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.show()
print(f"Area: {area}")
print(f"Perimeter: {perimeter}")
Subject to x + y ≥ 5
x≥4
y≤2
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 3.5 * x + 2 * y
prob += x + y >= 5
prob += x >= 4
prob += y <= 2
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Min Z= x + y
Subject to x ≥ 6
y≥6
x + y ≤ 11
x ≥ 0,y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += x + y
prob += x >= 6
prob += y >= 6
prob += x + y <= 11
prob.solve(pulp.PULP_CBC_CMD())
print(f"Status: {pulp.LpStatus[prob.status]}")
1) Apply python program each of the following transformations on the points P[3,-1]
Ans:
import numpy as np
P = np.array([3, -1])
P_reflected_x = reflection_x_matrix @ P
2) 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:-
Ans:
import numpy as np
A = np.array([4, -1])
B = np.array([3, 0])
theta = np.pi
[np.sin(theta), np.cos(theta)]])
A_rotated = A @ rotation_matrix
B_rotated = B @ rotation_matrix
SLIP NO:25
1)Write a python program to generate 3D plot of the functions z= sin x+ cos y in -10<x, y < 10.
Ans:
import numpy as np
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
2)Using python plot the graph of function f(x) = sin^{-1}x on the interval [-1,1]
Ans:
import numpy as np
x = np.linspace(-1, 1, 100)
y = np.arcsin(x)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()
3)Using python plot the surface plot of function z=cos(x^2-y^2-0.5) in the interval from -1 < x, y < 1.
Ans:
import numpy as np
x = np.linspace(-1, 1, 400)
y = np.linspace(-1, 1, 400)
x, y = np.meshgrid(x, y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
1)Rotate the line segment by 180° having end points (1,0) and (2,-1)
Ans:
import numpy as np
theta = np.radians(180)
[np.sin(theta), np.cos(theta)]])
plt.figure()
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
2)Using sympy declare the points P(5,2),Q(5,-2),R(5,0),cheak whether these points are collinear.Declare
the ray passing through the points P and Q find the length ogf the this ray between P and Q .Also find
slop of this ray
Ans:
import sympy as sp
P = sp.Point(5, 2)
Q = sp.Point(5, -2)
R = sp.Point(5, 0)
collinear = sp.Point.is_collinear(P, Q, R)
ray_PQ = sp.Ray(P, Q)
length_PQ = P.distance(Q)
print(f"The slope of the ray between P and Q is: {slope_PQ if slope_PQ is not None else 'undefined
(vertical line)'}")
3)Generate triangle with vertices (0,0),(4,0),(1,4) cheak whether the triangle is Scalene triangle.
Ans:
import numpy as np
A = np.array([0, 0])
B = np.array([4, 0])
C = np.array([1, 4])
AB = np.linalg.norm(B - A)
BC = np.linalg.norm(C - B)
CA = np.linalg.norm(A - C)
print(f"The triangle with vertices A{A}, B{B}, and C{C} is a scalene triangle: {is_scalene}")
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
Ans:
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
prob += 150 * x + 75 * y
prob += 4 * x + 6 * y <= 24
prob += 5 * x + 3 * y <= 15
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal Z: {pulp.value(prob.objective)}")
Max Z= 4x + y + 3z +5w
-3x - 2y +4z + w ≤ 10
-8x - 3y + 3z + 2w ≤ 20
x + y ≤ 11
x,y,z,w ≥ 0
Ans:
import pulp
y = pulp.LpVariable('y', lowBound=0)
z = pulp.LpVariable('z', lowBound=0)
w = pulp.LpVariable('w', lowBound=0)
prob += 4 * x + y + 3 * z + 5 * w
prob += 4 * x + 6 * y - 5 * z - 4 * w >= 20
prob += -3 * x - 2 * y + 4 * z + w <= 10
prob += -8 * x - 3 * y + 3 * z + 2 * w <= 20
prob += x + y <= 11
prob.solve()
print(f"Status: {pulp.LpStatus[prob.status]}")
print(f"Optimal x: {pulp.value(x)}")
print(f"Optimal y: {pulp.value(y)}")
print(f"Optimal z: {pulp.value(z)}")
print(f"Optimal w: {pulp.value(w)}")
import numpy as np
def apply_transformations(point):
matrices = [
return point
transformed_point = apply_transformations(point)
3)Write a python program to combined transformation on the line segment between the points A[3,2] &
B[2,-3] for the following sequence of transformations:-
import numpy as np
def apply_transformations(points):
matrices = [
return points
transformed_points = apply_transformations(points)