fsolve returns a strange value

3 views (last 30 days)
Takaaki Itoga
Takaaki Itoga on 27 Jan 2016
Commented: Walter Roberson on 27 Jan 2016
I am trying to solve two non-linear equations with two unknowns, using fsolve. Let me call the system of equations "PFI." When I just take the value of the equation at each x, say y=PFI(x), it returns values like [-1.5,-0.7]. This is not the root, but looks legit. However, when I use fsolve by writing [x0,y,exitflag1]=fsolve(@(x)PFI(x),x0,options), MATLAB returns the following:
[x0,y,exitflag1]=fsolve(@(x)PFI(x),x0,options)
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 3 3.49367e+23 0 1
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
selected value of the function tolerance.
<stopping criteria details>
x0 =
1.0000
0.1500
y =
1.0e+11 *
5.9107
0.0000
exitflag1 =
-2
I wonder why f(x) is so huge, and the first-order optimality is zero. The gradient at the initial point is not zero. I would appreciate it any comments. Thank you.
  1 Comment
Takaaki Itoga
Takaaki Itoga on 27 Jan 2016
I would like to add one more thing. This might occur because I call a Fortran subroutine in the equations.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 27 Jan 2016
fsolve has to invent new points to evaluate at. In the course of doing that, it has encountered a singularity. You probably need to be solving over a bounded region, but fsolve does not permit constraints.
You should be turning on Diagnostics and FunValCheck in the options structure.
  2 Comments
Takaaki Itoga
Takaaki Itoga on 27 Jan 2016
Thank you for your very prompt answer. I found another, probably worse problem. The value of the functions keep changing when I do not change inputs at all. I do not parallelize it, and there is no random variable involved...
Walter Roberson
Walter Roberson on 27 Jan 2016
That sounds as if your Fortran code might have an uninitialized variable.

Sign in to comment.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!