Kushgg

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

UNIVERSITY INSTITUTE OF ENGINEERING

Subject Name – Numerical Methods and Optimization Using Python

Course Code- 22CSH-259

Submitted To: Submitted By:

Faculty Name: Er. Savita Ma’am Name: Kushagra Kumar

UID: 22BCS14141

Section:TPP-818-A
Department of Computer Science & Engineering

INDEX
Exp. List of Experiments Conduct Viva Record Total Remarks
No (M.M:12) (M.M:8) (M.M:10) (M.M:30)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

WORKSHEET- 2

Student Name: Kushagra Kumar UID: 22BCS14141

Branch: BE-CSE Section/Group: TPP-818 ‘A’

Semester: 4th Date of Performance: 05/03/2024


Subject Name: Numerical Methods and Optimization Using Python
Subject Code: 22CSH-259

1. Aim:

A car manufacturer wants to optimize the fuel efficiency of their car by


adjusting the tire pressure. They have historical data on the fuel efficiency
of cars with different tire pressure and want to find the optimal tire pressure
that maximizes the fuel efficiency . You have been hired to develop a
python program that uses the secant method to find the optimal tire
pressure for the cars . The secant method is a numerical method used to
find the root of a function.

2. Source Code:

def fuel_efficiency(tire_pressure):
return -0.2 * tire_pressure**2 + 10 * tire_pressure - 100

def secant_method(func, x0, x1, tol=1e-6, max_iter=100):


for i in range(max_iter):
fx0 = func(x0)
fx1 = func(x1)
if abs(fx1) < tol:
return x1
x_next = x1 - (fx1 * (x1 - x0)) / (fx1 - fx0)
x0, x1 = x1, x_next
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

print("Max iterations reached. Solution may not be accurate.")


return x1

def main():

tire_pressure_data = [28, 30, 32, 34, 36]


fuel_efficiency_data = [45, 48, 50, 46, 42]

initial_guesses = [30, 32]


for guess in initial_guesses:
optimal_tire_pressure = secant_method(fuel_efficiency, guess - 1,
guess + 1)
optimal_fuel_efficiency = fuel_efficiency(optimal_tire_pressure)

print(f"Optimal tire pressure: {optimal_tire_pressure:.2f} psi")


print(f"Optimal fuel efficiency: {optimal_fuel_efficiency:.2f}
mpg\n")

if __name__ == "__main__":
main()

3. Screenshot of Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Learning Outcomes:

1. Understanding Numerical Methords.


2. Data analysis and interpretation.
3. Problem skills.
4. Application of Numerical Methords.
5. Secant Methords.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like