-2

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?

Neuron
  • 5,141
  • 5
  • 38
  • 59
every1
  • 1
  • 1

1 Answers1

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