Least-squares minimization (least_squares)
The code below implements least-squares estimation of and finally plots the original data and the fitted model function:X
scipy.optimize.least_squares(fun, x0, jac=‘2-point’, bounds=(- inf, inf), method=‘trf’, ftol=1e-08, xtol=1e-08, gtol=1e-08, x_scale=1.0, loss=‘linear’, f_scale=1.0, diff_step=None, tr_solver=None, tr_options={}, jac_sparsity=None, max_nfev=None, verbose=0, args=(), kwargs={})
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 4 22:43:05 2021
@author: Machi
"""
from scipy.optimize import least_squares
import numpy as np
import matplotlib.pyplot as plt
def model(x, u):
return x[0] * (u ** 2 + x[1] * u) / (u ** 2 + x[2] * u + x[