Skip to content
Advertisement

Numerical Solutions for System of Non-Linear Equation in Python

I have 2 simple equations:

JavaScript

These equations can be solved analytically where k = 5.77 and h = 8.47. I tried to solve it in Python using fsolve and I have followed the way from: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html#scipy.optimize.fsolve

Below is my code:

JavaScript

And the result is

JavaScript

I am not sure what I did wrong here such that I did not get the correct result. Would you like to point my mistake for this problem? Thank you.

Advertisement

Answer

  1. fsolve does not know that your variables are non-negative. The solver goes into the negative zone (because from (1, 1) gradients tell to go towards the negative zone), gets NaNs there, and gets stuck. You should tell somehow where you are looking for a solution. fsolve does not support bounds directly. least_squares can do this.

  2. There are several solutions. (0, 0) is also fit. You probably have to somehow push away from it, because it seems not what you want to get from a solver.

You may try something like that.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement