fsolve No Solution found (but there is one)

Hello everyone,
I have checked in other posts having the same problem but, given the specificity of those, the proposed solutions do not apply to my case. However, I believe my situation is even simpler. I just need a little guidance.
Basically I am using fsolve for solving one non-linear equation F(x)=0. I am sure the solution exists as when I plot the function I can see the point.
However I receive this message
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 default value of the function tolerance.
I suppose it is happening as, despite the look of the graph given the plot range, the solution is in a region where the function is almost flat (between 2.5*10^9 and 3.5*10^9).
I tried to change the starting point, increase the TolFun/TolX but it still produces the same error.
What should I do? Increase TolFun and decrease TolX maybe?
Thank you

2 Comments

Could you post your code?
Specifically at least the function. You might try standardizing the variables to increase dynamic range somewhat but looks like fsolve should have no problem unless there's something funky going on in the neighborhood of the solution that is hidden by the scaling.
Try blowing up the plot in the ROI and see if the smoothness apparent here is really not so smooth...

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 31 Aug 2017
Edited: Matt J on 31 Aug 2017
For starters, fsolve is overkill for a one-variable monotonic function. You could just as well use fzero.
Second, you could adjust TolX or TolFun, but I would instead rescale the function so that the factors of 10^9 both in input and output space go away.
F_new(x)=F_old(x*10^9)/10^9;

9 Comments

Hi Matt J, thank you for your reply. I had thought that the problem could be the scale and, despite your comment being very useful, unfortunately it does not solve the problem... Here is the graph of the rescaled function
The solution is evidently around 3 but if I code fsolve(f_new,3) it produces the same error.
Do you have any suggestions on how increase/decrease TolFun and TolX?
Thank you
About fzero vs fsolve, the function looks nice graphically but it expression is far from being trivial. fzero is not able to find the solution.
You're still not providing what the function is.
The complexity of the expression shouldn't determine whether or not fzero is applicable.
I think we need to see some code.
The code (and the relative data needed to run) are attached.
Let me try to explain what is about. There are a series of equations that need to be solved recursively. Solving the first, its solution enters in the second equation as a parameter and the second solution needs to be determined. And so on....
The procedure works until the third equation (in the file f3_new is solved by fsolve). When I try to solve the fourth (f4_new) I get the error above mentioned. The function belongs to a certain 'family' of functions (they look similar) but at each iteration the complexity increases.
Equation 1 is an integral equation which involves univariate Gaussian intergrals; Equation 2 is an integral equation which involves bivariate Gaussian integrals; and so on...
I know the code is 'ugly' but I was not able to write it in a for loop, so each step is explicitly calculated.
Thank you very much for your support.
You will see that if you try to use fzero, an error (related to the erfc function) is produced.
Well, I had better luck with fzero than with fsolve,
>> [x,fval]=fzero(f4_new,[1,5])
x =
2.8404
fval =
1.5939e-07
>> [x,fval]=fsolve(f4_new,2.8)
x =
2.8000
fval =
-0.0275
The reason fsolve is doing poorly is probably due to the lack of smoothness in the function observed below. So dpb was right, however, it's not at all clear to me what's causing the non-smoothness.
Thank you very much!
The roughness comes from the iterative nature of the solution in prior steps. I've not tried, but I'd guess a better solution in the previous would lead to smoother results later on although that's not guaranteed--it might be a pathological case that the discontinuities become more and more pronounced instead.
The indication of an error in erfc is evidence of how sensitive the internals are.

Sign in to comment.

More Answers (0)

Asked:

on 31 Aug 2017

Edited:

on 1 Sep 2017

Community Treasure Hunt

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

Start Hunting!