Home > Blockchain >  Fsolve precision issue (python)
Fsolve precision issue (python)

Time:12-12

I am experiencing precision issue with fsolve.

import numpy as np
from scipy.optimize import fsolve


ens=np.arange(0,50,1)


def f(x):
     return x*(np.sin(x)/np.cos(x))-1000

s=[]        

roots=fsolve(f,ens)
roots=np.around(roots, decimals=3 , out=None)
a = roots[roots >= 0]
g = np.unique(a)
g=g[:5]
s.append(g)
print(s)
            

result :

[array([10.842, 11.006, 15.165, 21.116, 22.382])]

The result should be : [1.569,4.708,7.846,10.985,14.123]

My code miss the first three solutions, and the others are not accurate. Do you know how could I improve the precision of my results ?

CodePudding user response:

You can use enter image description here

  • Related