Project 19: Energy Cost Optimizer
Scientific Computing
Current Task
Objective
Review day: use a physical constant — day 4 — inside an optimization — day 5.
Task: minimize an energy cost function that uses scipy.constants.g, and print the result.
index.py
from scipy import constants
from scipy.optimize import minimize
def energy_cost(mass):
return (mass[0] * constants.g - 500) ** 2
result = minimize(energy_cost, x0=[10])
print(result.x.round(2))
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview