#program to find solution of quadratic equation
#Name and Roll
#Quadratic equation is of the order ax^2+bx+c=0
import math
import cmath
print("Quadratic equation is of the order a*x^2+b*x+c=0 \n where a=coefficient of x^2\
nb=coefficient of b and\nc=constant")
#taking coefficient a,b and c from user
a=float(input("Enter coefficient of(x^2)"))
b=float(input("Enter coefficient of(x)"))
c=float(input("Enter value of constant"))
s=b**2-(4*a*c)
if(s>0):
s1=((-1*b)+math.sqrt(s))/(2*a)
s2=((-1*b)-math.sqrt(s))/(2*a)
print("The roots are real and unequal and are given by \nxt=",s1,"and x2=",s2)
if(s==0):
s1=((-1*b)+math.sqrt(s))/(2*a)
s2=((-1*b)-math.sqrt(s))/(2*a)
print("The roots are real and equal and are given by \nxt=",s1,"and x2=",s2)
if(s<0):
s1=((-1*b)+cmath.sqrt(s))/(2*a)
s2=((-1*b)-cmath.sqrt(s))/(2*a)
print("The roots are imaginary and are given by \nxt=",s1,"and x2=",s2)
Monday, 10 March 2025
Python program to find solution of quadratic equation
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Copy Copied! #Program to print any table of any number entered by user #Name and Roll Number import...
-
Copy Copied! #program to find solution of quadratic equation #Name and Roll #Quadratic equation i...
-
Copy Copied! #Experiment No 4:Program to solve a linear differential equation using SciKit and pol...
plt.scatter(xc.yc, color='red', label="Control Points")
ReplyDeleteplt.title("%d-Degree Bezier Curve"%n)
plt.annotate("Convex Hull, xy=(xe[1],ye[1]).
xytext=(x[1]-0.5. ye[1]-0.5),
arrowprops=dict(facecolor='green',
shrink=0.05).)
plt.xlabel('x-axis!)
plt.ylabel('y-axis)
plt.legend({"n-degree Bezier Curve", "Convex Hull"], loc="upper right")
pit.grid()
plt.show()
#Program to solve n-variable simultaneous equation Ax+By+Cz=D
ReplyDeleteimport numpy as np
3
#taking input of left hand side into a matrix
print('Program to solve Simulataneous equation of the order Ax+By+Cz=D for n-variable')
m=int(input('Enter number of Simultaneous Equation to solve: '))
n=int(input('Enter number of variable in the Simultaneous Equations: '))
ar=np.zeros([m,n])
print('ar=\n',ar)
print("Please enter coefficients of variable in a single line and seperated by a space: ")
c=list(map(int,input().split()))
Camp.array(c).reshape(m,n)
print('Updated Array=\n',ar)
print('Enter the constant (right hand side) values seperated by space')
e=list(map(int,input().split()))
ReplyDeletear2=np.array(e).reshape(m,1)
print(ar2)
#calculating inverse of martix
res=np.dot(np.linalg.inv(ar),ar2)
print(len(res))
#printing the values of the solution of simultaneous Equation print("\nSolution of Simultaneous Equations is given by:\n') for i in res:
for j in i:
print('x',j,end='')
print()
#Experiment No.8(b)-Program to find deflection of simply supported Beam
ReplyDeleteimport numpy as np
import matplotlib.pyplot as plt
# User input
l = float(input("Enter the length of beam in mm: ")) / 1000 # Convert mm to Meters
b = float(input("Enter the breadth of beam in mm: ")) / 1000 # Convert mm to Meters
h = float(input("Enter the height of beam in mm: ")) / 1000 # Convert mm to Meters
E = float(input("Enter the Young's Modulus of beam Material in MPa: ")) * 1e6 # Convert MPa to
Pascals
density = float(input("Enter the density of beam material in kg/m^3: "))
# Cross-sectional area and moment of inertia
A = b * h
I = (b * h**3) / 12 # Moment of inertia for a rectangular section
# Distributed load per unit length (self weight)
w = density * A * 9.81 # N/m (Gravity applied)
# Generate discrete points along the beam length
x = np.linspace(0, l, 100) # 100 Points for smooth curve
# Apply the exact formula for deflection at each point
deflection = (w * x * (l**3 - 2 * l * x**2 + x**3)) / (24 * E * I)
# Calculate max deflection at the center
delta_max = (5 * w * l**4) / (384 * E * I)
print(f"Maximum deflection at the center of the beam: {delta_max * 1000:.4f} mm")
# Plotting the deflection
plt.figure(figsize=(8, 6))
plt.plot(x * 1000, deflection * 1000, label='Beam Deflection', color='blue')
plt.title('Deflection of Simply Supported Beam under Self Weight')
plt.xlabel('Length of Beam (mm)')
plt.ylabel('Deflection (mm)')
plt.grid(True)
plt.legend()
plt.show()