ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)
Set your Publisher ID in src/config/ads.ts to display live ads.
SciPy Scientific Computing Tutorial• 6 min read
SciPy Optimizers & Root Finding
Master finding local minima and non-linear roots using the scipy.optimize module.
Root Finding with root()
Finding the root of an equation means locating the values of x where f(x) = 0. SciPy provides the general-purpose scipy.optimize.root function.
Finding Roots of an Equation
from scipy.optimize import root
import math
def equation(x):
# Solve: x + cos(x) = 0
return x + math.cos(x)
result = root(equation, x0=0)
print("Root location x:", round(float(result.x[0]), 4))
print("Did convergence succeed?:", result.success)Minimizing Objective Functions
In machine learning, cost modeling, and engineering, minimizing an objective function is central. The scipy.optimize.minimize function finds the local minimum of a function with optional bounds and constraints.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)
Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
Which SciPy function is used to locate the minimum of a continuous objective function?