Quantcast
Channel: ASKSAGE: Sage Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 11

Using Sage Symbolic Functions in Scipy fsolve

Previous: Answer by Felix Lawrence for I need to find the roots of a system of multivariate non-linear (algebraic) functions and Sage's solve function is running indefinitely. (Where "indefinitely" means "more than 30 mins".) I only require numerical solutions so I was hoping to use Scipy's fsolve function instead. However, the functions that I'm generating are Sage symbolic functions, which have been mightly convenient to work with, and I'm having trouble getting them into a format that fsolve will understand. Does anyone have any suggestions?The documentation for Scipy's fsolve can be found here. It looks like a Python function is sufficient.As a toy example, I've tried the following:sage: from scipy.optimize import fsolve sage: var('x,y') sage: f = x^2 + y^2 sage: def ff(v): return f(x=v[0],y=v[0]) sage: fsolve(ff,[1,1]) It seems like the naive approach but I'm receiving the error TypeError: no canonical coercion from <type 'numpy.int64'> to Symbolic Ring. Perhaps this is an issue with Sage properly dealing with Numpy/Scipy data types?
$
0
0
I need to find the roots of a system of multivariate non-linear (algebraic) functions and Sage's ``solve`` function is running indefinitely. (Where "indefinitely" means "more than 30 mins".) I only require numerical solutions so I was hoping to use Scipy's ``fsolve`` function instead. However, the functions that I'm generating are Sage symbolic functions, which have been mightly convenient to work with, and I'm having trouble getting them into a format that ``fsolve`` will understand. Does anyone have any suggestions? The documentation for Scipy's ``fsolve`` can be found [here](http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html#scipy.optimize.fsolve). It looks like a Python function is sufficient. As a toy example, I've tried the following: sage: from scipy.optimize import fsolve sage: var('x,y') sage: f = x^2 + y^2 sage: def ff(v): return f(x=v[0],y=v[0]) sage: fsolve(ff,[1,1]) It seems like the naive approach but I'm receiving the error ``TypeError: no canonical coercion from to Symbolic Ring``. Perhaps this is an issue with Sage properly dealing with Numpy/Scipy data types?

Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles



Latest Images