SLIP NO :1
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].
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1, 1, 100)
plt.plot(x, x2, label=’f(x) = x2′)
plt.plot(x, x3, label=’g(x) = x3′)
plt.legend()
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 matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5, 5, 100)
plt.plot(x, np.exp(-x), ‘g–‘, marker=’^’, label=’f(x) = e^(-x)’)
plt.xlabel(“x”)
plt.ylabel(“f(x)”)
plt.legend()
plt.show()
3) Using python,represent the following information using bar graph (colour=green).
Item =[clothing ,food ,rent, petrol,misc]
Expenditure in Rs=[600,4000,2000,1500,700]
import matplotlib.pyplot as plt
items = [‘Clothing’, ‘Food’, ‘Rent’, ‘Petrol’, ‘Misc’]
expenditure = [600, 4000, 2000, 1500, 700]
plt.bar(items, expenditure, color=’green’)
plt.xlabel(‘Items’)
plt.ylabel(‘Expenditure in Rs’)
plt.show()
Q 2) Attempt any two of the following .
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.
import sympy as sp
def reflect_point(x, y):
P = sp.Point(x, y)
line = sp.Line(sp.Point(0, 1), slope=1)
P_reflected = P.reflect(line)
return P_reflected
A = reflect_point(5, 3)
B = reflect_point(1, 4)
print(“Reflected point A:”, A)
print(“Reflected point B:”, B)
2) Write a python program draw polygon with vertices(0,0),(2,0),(2,3) and (1,6) and rotate by 180°.
import matplotlib.pyplot as plt
import numpy as np
vertices = np.array([[0, 0], [2, 0], [2, 3], [1, 6], [0, 0]])
rotation_matrix = np.array([[-1, 0], [0, -1]])
rotated_vertices = vertices @ rotation_matrix
plt.figure()
plt.plot(vertices[:, 0], vertices[:, 1], marker=’o’)
plt.plot(rotated_vertices[:, 0], rotated_vertices[:, 1], marker=’x’)
plt.grid()
plt.axhline(0, color=’gray’, linewidth=0.5)
plt.axvline(0, color=’gray’, linewidth=0.5)
plt.legend()
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]
A = (0, 0)
B = (5, 0)
C = (3, 3)
perimeter = ((B[0] – A[0])2 + (B[1] – A[1])2)0.5 + \ ((C[0] – B[0])2 + (C[1] – B[1])2)0.5 + \
((A[0] – C[0])2 + (A[1] – C[1])2)**0.5
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 of the triangle: {perimeter:.2f}”)
print(f”Area of the triangle: {area:.2f}”)
Q 3) Attempt the following.
A)Attempt Any one of the following .
1) Write the python program to solve following LPP
I) Max Z=150x+75y
Subject to 4x + 6y ≤ 24.
5x + 3y ≤ 15.
x ≥ 0,y ≥0.
import pulp as p
lp = p.LpProblem(“Maximize_Z”, p.LpMaximize)
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
lp += 150 * x + 75 * y
lp += 4 * x + 6 * y <= 24 # Constraint 1
lp += 5 * x + 3 * y <= 15 # Constraint 2
lp.solve()
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}”)
PYTHON PROGRAMMING LANGUAGE=I
SLIP NO:2
Q 1) Attempt any two of the following .
1) Write a Python program to 2D graphs to the functions f(x)=log₁₀(x)in interval [0,10].
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10)
y = np.log10(x)
plt.plot(x,y)
plt.show()
3) Using python ,draw a bar graph in GREEN to represent the data below:
Subject =[Math, Scinece,English ,Marathi ,Hindi].
Percentage of passing =[68,90,70,85,91].
import matplotlib.pyplot as plt
subject = [‘Maths’,’science’,’english’,’marathi’,’hindi’]
percentage = [68,90,70,85,91]
plt.bar(subject , percentage , color =’green’)
plt.show()
Q 2) Attempt any two of the following .
1) Using sympy declare the points A(0,2), B(5,2),C(3,0) check whether these points are collinear .Declare
the line passing through points A & B find the distance of these line from point C.
from sympy import Point, Line, sqrt
A = (0, 2)
B = (5, 2)
C = (3, 0)
area = 0.5 * abs(A[0](B[1] – C[1]) + B[0](C[1] – A[1]) + C[0](A[1] – B[1])) if area == 0: print(“Points A, B, and C are collinear.”) else: print(“Points A, B, and C are not collinear.”) line_AB = Line(A, B) distance = line_AB.distance(C) print(f”Distance of point C from line AB: {distance:.2f}”) 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) AB = math.sqrt((B[0] – A[0])2 + (B[1] – A[1])2) BC = math.sqrt((C[0] – B[0])2 + (C[1] – B[1])2) CA = math.sqrt((A[0] – C[0])2 + (A[1] – C[1])2) perimeter = AB + BC + CA area = abs(A[0]B[1] + B[0]C[1] + C[0]A[1] – A[1]B[0] – B[1]C[0] – C[1]*A[0]) / 2
print(f”Perimeter of ΔABC: {perimeter}”)
print(f”Area of ΔABC: {area}”)
Q 3) Attempt the following .
A) Attempt any one of the following .
I) Write a python program to solve LPP:
Max Z=5x + 3y
Subject to x + y ≤ 7.
2x + 5y ≤ 1.
X ≥ 0,y ≥ 0
import pulp as p
lp = p.LpProblem(“Maximize_Z”, p.LpMaximize)
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
lp += 5 * x + 3 * y
lp += x + y <= 7
# Constraint 1
lp += 2 * x + 5 * y <= 1 # Constraint 2
lp.solve()
if p.LpStatus[lp.status] == ‘Optimal’:
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}”)
else:
print(“No optimal solution exists.”)
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
import pulp as p
lp = p.LpProblem(“Maximize_Z”, p.LpMaximize)
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
z = p.LpVariable(“z”, lowBound=0)
lp += 3 * x + 2 * y + 5 * z
lp += x + 2 * y + z <= 430 # Constraint 1
lp += 3 * x + 2 * z <= 460 # Constraint 2
lp += x + 4 * y <= 120
lp.solve(p.PULP_CBC_CMD(msg=True)) # Display solver output
if p.LpStatus[lp.status] == ‘Optimal’:
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}, z = {p.value(z):.2f}”)
else:
print(“No optimal solution exists.”)
B) Attempt any of the following .
1) Apply python program of each of the following transformation on point P[3,-1].
I) Refection through x-axis .
II) Scalling on x-coordinate by factor 2.
III) Scalling on y-coordinate by factor 1.5 .
IV) Refection through line y = x.
P = (3, -1)
P_x_axis = (P[0], -P[1])
P_scale_x = (2 * P[0], P[1])
P_scale_y = (P[0], 1.5 * P[1])
P_reflect_line = (P[1], P[0])
print(f”Original Point P: {P}”)
print(f”Reflection through x-axis: {P_x_axis}”)
print(f”Scaling on x-coordinate by 2: {P_scale_x}”)
print(f”Scaling on y-coordinate by 1.5: {P_scale_y}”)
print(f”Reflection through the line y = x: {P_reflect_line}”)
SLIP NO: 3
Q 1) Attempt any two of the following .
1) Using python plot the graph of function f(x)= cos (x) on the interval [0,2π].
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,2*(np.pi),0.1)
y = np.cos(x)
plt.plot(x,y)
plt.show()
2) Following is the information of students participating in various game in a school.Represent it a by Bar
graph with bar width of 0.7 inches .
Game =[Cricket ,Football ,Hockey ,Chess ,Tennis].
Number of students=[65,30 54,10,20].
import matplotlib.pyplot as plt
import numpy as np
game = [‘Cricket’,’football’,’hockey’,’chess’,’tennis’]
student = [65,30,54,10,20]
plt.bar(game,student, width=0.7,color=’skyblue’)
plt.xlabel(‘game’)
plt.ylabel(‘student’)
plt.show()
Q 2) Attemprt any two of the following .
1) Write a python program to reflect line segment joining the points A[5,3] and B[1,4] through line
y=x+1.
import sympy as sp
def reflect_point(x, y):
P = sp.Point(x, y)
line = sp.Line(sp.Point(0, 1), slope=1)
P_reflected = P.reflect(line)
return P_reflected
A = reflect_point(5, 3)
B = reflect_point(1, 4)
print(“Reflected point A:”, A)
print(“Reflected point B:”, B)
3) Generate the line segment having endpoints (0,0) and (10,10) . Find the mid points of line segment
A = (0, 0)
B = (10, 10)
midpoint = ((A[0] + B[0]) / 2, (A[1] + B[1]) / 2)
print(f”Endpoints of the line segment: A{A}, B{B}”)
print(f”Midpoint of the line segment: {midpoint}”)
Q 3) Attempt the following .
A) Attempt any one of the following.
1) Write a program to solve the following LPP :
Min Z = 3.5 x +2y
Subject to x + y ≥ 5
x ≥ 4
y ≤ 2
x ≥ 0, y ≥ 0
import pulp as p
Create a Linear Programming problem (Minimization)
lp = p.LpProblem(“Minimize_Z”, p.LpMinimize)
Define variables with lower bounds
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
Objective function
lp += 3.5 * x + 2 * y, “Objective”
Constraints
lp += x + y >= 5
lp += x >= 4
lp += y <= 2
# Constraint 1
Constraint 2
# Constraint 3
Solve the problem
lp.solve()
Display the results
if p.LpStatus[lp.status] == ‘Optimal’:
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}”)
else:
print(“No optimal solution exists.”)
B) Attempt any one of the following .
1) Apply pythonnprogram in each of the following transformation on the point P[4,-2]
I)
Refection through Y -axis .
II)
Scaling in X-coordinate by factor 3.
III)
Scaling in Y-coordinate by factor 2.5
IV)
Reflection through the line y=x.
Original point
P = [4, -2]
I) Reflection through Y-axis
P_reflect_y_axis = [-P[0], P[1]]
II) Scaling in X-coordinate by factor 3
P_scale_x = [P[0] * 3, P[1]]
III) Scaling in Y-coordinate by factor 2.5
P_scale_y = [P[0], P[1] * 2.5]
IV) Reflection through the line y = x
P_reflect_line_yx = [P[1], P[0]]
Displaying the results
print(“Original Point P:”, P)
print(“I) Reflection through Y-axis:”, P_reflect_y_axis)
print(“II) Scaling in X-coordinate by factor 3:”, P_scale_x)
print(“III) Scaling in Y-coordinate by factor 2.5:”, P_scale_y)
print(“IV) Reflection through the line y = x:”, P_reflect_line_yx)
SLIP NO =4
Q 1) Attempt any two of the following .
1)Write a Python program to 2D graphs to the functions f(x)=log₁₀(x)in interval [0,10].
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10)
y = np.log10(x)
plt.plot(x,y)
plt.show()
2)Using python plot the graph of function f(x)=sin⁻¹ (x) interval [-1,1].
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-1,1,0.01)
y = np.arcsin(x)
plt.plot(x,y)
plt.show()
Q 2) Attempt any two of the following .
1) If the line with points A[3,1] , B [ 5,-1] is transformed by the transformation matrix [T]=[3 -2
2 1] then using python, find the equation of transformed line.
2) Write a python program draw polygon with vertices(0,0),(2,0),(2,3) and (1,6) and rotate by 180°.
import matplotlib.pyplot as plt
import numpy as np
vertices = np.array([[0, 0], [2, 0], [2, 3], [1, 6], [0, 0]])
rotation_matrix = np.array([[-1, 0], [0, -1]])
rotated_vertices = vertices @ rotation_matrix
plt.figure()
plt.plot(vertices[:, 0], vertices[:, 1], marker=’o’)
plt.plot(rotated_vertices[:, 0], rotated_vertices[:, 1], marker=’x’)
plt.grid()
plt.axhline(0, color=’gray’, linewidth=0.5)
plt.axvline(0, color=’gray’, linewidth=0.5)
plt.legend()
plt.show()
2) Write a python program to draw a polygon with vertices (0,0),(2,0),(2,3) & (1,6 ) and rotate it by 180∘
import matplotlib.pyplot as plt
Original vertices
x = [0, 2, 2, 1, 0]
y = [0, 0, 3, 6, 0]
Plot original polygon
plt.plot(x, y)
Rotate by 180° (negate coordinates)
x_rotated = [-i for i in x]
y_rotated = [-i for i in y]
Plot rotated polygon
plt.plot(x_rotated, y_rotated)
Add labels and grid
plt.grid()
plt.legend()
plt.show()
3) Using python generate line passing through points (2,3) & (4,3) and find equation of the line.
Given points
x1, y1 = 2, 3
x2, y2 = 4, 3
Calculating the slope
m = (y2 – y1) / (x2 – x1)
Since the line is horizontal, y-intercept b is the same as y-coordinate
b = y1 # or y2 since y1 == y2
Equation of the line
equation = f”y = {m}x + {b}” if m != 0 else f”y = {b}”
print(equation)
Q 3) Attempt the following.
A) Attempt any one of the following .
1) Write the python program to solve the following LPP.
Max Z= 150x + 75y
Subject to 4x + 6y ≤ 24
5x + 3y ≤ 15
x ≥ 0, y ≥ 0
import pulp as p
Create a Linear Programming problem (Maximization)
lp = p.LpProblem(“Maximize_Z”, p.LpMaximize)
Define variables with lower bounds
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
Objective function
lp += 150 * x + 75 * y, “Objective”
Constraints
lp += 4 * x + 6 * y <= 24, “Constraint 1”
lp += 5 * x + 3 * y <= 15, “Constraint 2”
Solve the problem
lp.solve()
Display the results
if p.LpStatus[lp.status] == ‘Optimal’:
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}”)
else:
print(“No optimal solution exists.”)
B) Attempt any one of the following .
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.
I)
Shearing in X-direction by 9 units.
II)
Rotaion about origin through an angle π .
III)
Scaling in X-coordinate by 2 units.
IV)
Reflecton through the line y=x.
import numpy as np
A, B = np.array([4, -1]), np.array([3, 0])
shear = np.array([[1, 9], [0, 1]])
rotate = np.array([[-1, 0], [0, -1]])
scale = np.array([[2, 0], [0, 1]])
reflect = np.array([[0, 1], [1, 0]])
A = reflect @ scale @ rotate @ shear @ A
B = reflect @ scale @ rotate @ shear @ B
print(“Transformed A:”, A)
print(“Transformed B:”, B)
SLIP NO =5
Q 1) Attempt any two of the following .
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.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def f(x, y):
return np.cos(x2 – y2 – 0.5)
x = np.linspace(-1, 1, 50)
y = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure(figsize=(8, 6))
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].
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def f(x, y):
return np.sin(x2 + y2)
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection=’3d’)
ax.plot_surface(X, Y, Z, cmap=’plasma’)
ax.set_xlabel(‘X-axis’)
ax.set_ylabel(‘Y-axis’)
ax.set_zlabel(‘Z-axis’)
ax.set_title(‘3D Surface Plot of f(x, y) = sin(x² + y²)’)
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.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def f(x, y):
return np.sin(x) + np.cos(y)
x = np.linspace(-10, 10, 200)
y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection=’3d’)
ax.plot_surface(X, Y, Z, cmap=’coolwarm’)
ax.set_xlabel(‘X-axis’)
ax.set_ylabel(‘Y-axis’)
ax.set_zlabel(‘Z-axis’)
ax.set_title(‘3D Surface Plot of z = sin(x) + cos(y)’)
plt.show()
Q 2) Attempt any two of the following .
1) Using python to generate triangle with vertices(0,0),(4,0),(4,3) cheak wheather triangle is Right angle
triangle
Ans:
import math
A, B, C = (0, 0), (4, 0), (4, 3)
AB, BC, AC = math.dist(A, B), math.dist(B, C), math.dist(A, C)
print(“Right-angled” if AB2 + BC2 == AC**2 else “Not Right-angled”)
2) Generate the vector x in the interval [-7,7] using numpy package with subintervals.
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
A, B, C = (0, 0), (6, 0), (4, 4)
AB, BC, CA = math.dist(A, B), math.dist(B, C), math.dist(C, A)
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}”)
Q 3) Attempt the following.
A)
Attempt any one of the following.
I) Write a python program solvethe following LPP:
Max Z=5x + 3y
Subject to x + y ≤ 7
2x + 5y ≤ 1
x ≥ 0,y ≥0.
import pulp as p
Create a Linear Programming problem (Maximization)
lp = p.LpProblem(“Maximize_Z”, p.LpMaximize)
Define variables with lower bounds
x = p.LpVariable(“x”, lowBound=0)
y = p.LpVariable(“y”, lowBound=0)
Objective function
lp += 150 * x + 75 * y, “Objective”
Constraints
lp += 4 * x + 6 * y <= 24, “Constraint_1”
lp += 5 * x + 3 * y <= 15, “Constraint_2”
Solve the problem
lp.solve()
Display the results
if p.LpStatus[lp.status] == ‘Optimal’:
print(f”Optimal value of Z: {p.value(lp.objective):.2f}”)
print(f”Optimal values: x = {p.value(x):.2f}, y = {p.value(y):.2f}”)
else:
print(“No optimal solution exists.”)
B)
Attempt any one of the following.
1)
Apply python program in each of the following transformation on the point P[3,8]
I)
refection through X-axis
II)
Scaling in x coordinate by factor 6.
III)
Rotation about oringin through an angle 30°.
IV)
Reflection through the line y= -x.
Ans:
import numpy as np
P = np.array([3, 8])
P = np.array([P[0], -P[1]])
P = np.array([6 * 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}”)