find a zero of a system of n nonlinear functions
[x, v, info] = fsolve(x0, fct) [x, v, info] = fsolve(x0, fct, fjac) [x, v, info] = fsolve(x0, fct, fjac, tol) [x, v, info] = fsolve(x0, fct, tol)
real vector (initial value of function argument).
external (i.e function or list or string).
external (i.e function or list or string).
real scalar. precision tolerance: termination occurs when the
algorithm estimates that the relative error between x and the
solution is at most tol. (tol=1.d-10
is the
default value).
real vector (final value of function argument, estimated zero).
optional real vector: value of function at x.
optional termination indicator:
0 | improper input parameters. |
---|---|
1 | algorithm estimates that the relative error between x and the solution is at most tol. |
2 | number of calls to fcn reached |
3 | tol is too small. No further improvement in the approximate solution x is possible. |
4 | iteration is not making good progress. |
find a zero of a system of n nonlinear functions in n variables by a modification of the powell hybrid method. Jacobian may be provided.
fct
is an "external". This external returns
v=fct(x)
given x
.
The simplest syntax for fct
is:
If fct
is a character string, it refers to a C or
Fortran routine which must be linked to Scilab. Fortran calling sequence
must be
fct(n,x,v,iflag) integer n,iflag double precision x(n),v(n) | ![]() | ![]() |
and C Syntax must be
Incremental link is possible (help link
).
jac
is an "external". This external returns
v=d(fct)/dx (x)
given x
.
The simplest syntax for jac
is:
If jac
is a character string, it refers to a to a
C or Fortran routine which must be linked to Scilab calling sequences are
the same as those for fct. Note however that v must be a nxn array.
For some starting points and some equations system, the fsolve method can fail. The fsolve method is a local search method. So, to have a good chance to find a solution to your equations system, you must ship, a good starting point to fsolve.
Here is an example on which fsolve can fail:
// Another example with fsolve function F=feuler(x, r) F=x-r-dt*(x.^2-x.^3); endfunction function J=dFdx(x) //Definition of the Jacobian J=1-dt*(2*x-3*x^2); endfunction r = 0.04257794928862307 ; dt = 10; [x,v,info]=fsolve(r,list(feuler,r),dFdx); // fsolve do not find the solution disp(v); // The residual disp(info); // The termination indicator [x,v,info]=fsolve(1,list(feuler,r),dFdx); // fsolve find the solution disp(v); // The residual disp(info); // The termination indicator clf(); x=linspace(0,1,1000); plot(x,feuler(x)) a=gca(); a.grid=[5 5]; | ![]() | ![]() |
So, each time you use fsolve, be sure to check the termination indicator and the residual value to see if fsolve has converged.