I need to calculate the error in each iteration at solving a system of equation non-linear with fsolve
in python, like resnorm
of fsolve
in MATLAB. Someone can help me if it's possible in python?
Asked
Active
Viewed 241 times
-2
-
Please share what you have tried so far – HoRn Sep 01 '21 at 06:19
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 02 '21 at 17:07
1 Answers
0
This can be easily achieved by peeking at the docs.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
# Use the function from the docs
def func(x):
return [x[0] * np.cos(x[1]) - 4,
x[1] * x[0] - x[1] - 5]
roots_dict = fsolve(func, x0 = [1,1], full_output = True)
# calculate the square sum of the residuals:
res = np.sum(roots_dict[1]['fvec'] ** 2)
The sum of the square of the residuals will be:
res
>> 2.754320890449926e-22

liorr
- 764
- 5
- 21