fsolve stopped because the problem appears regular

99 views (last 30 days)
Hi,
I am trying to solve a simple problem but somehow stuck with the output:
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.
Would appreciate some help!
function F = root2d(x)
F(1) = (39*x(1)^2*x(2)^2)/100 - (x(2)^2)/5 - 2*x(1)^2 + 1;
F(2) = (39*x(1)^2*x(2)^2)/100 - (7*x(2)^2)/25 - (14*x(1)^2)/5 + 49/25
And my script says
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
Thanks a lot in advance!
  1 Comment
XIN
XIN on 24 Sep 2022
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
value of the function tolerance.
<stopping criteria details
Question: Why am I having this problem with kmv in matlab? My percentage data are turned into numerical values, but after calculating, my asset value and Equity's value are exactly the same, and the asset value volatility is all 1. I find it so strange.
1、kmvbatch.m
m=xlsread('data1.xlsx',1,'A1:F36')
for i=1:36
r=m(i,4);%
EquityTheta = m(i,1);
E = m(i,2);
D = m(i,3);
T=1;
[Va,AssetTheta] = KMVOptSearch(E,D,r,T,EquityTheta)
m(i,5)=Va;
m(i,6)=AssetTheta;
end
m %
xlswrite('2.csv',m)
2、kmvfun.m
function F=KMVfun(EtoD,r,T,EquityTheta,x)
d1=(log(x(1)*EtoD)+(r+0.5*x(2)^2)*T)/(x(2)*sqrt(T));
d2=d1-x(2)*sqrt(T);
F=[x(1)*normcdf(d1)-exp(-r*T)*normcdf(d2)/EtoD-1;
normcdf(d1)*x(1)*x(2)-EquityTheta];
end
3、kmvoptsearch
function [Va,AssetTheta]=KMVOptSearch(E,D,r,T,EquityTheta)
EtoD=E/D;
x0=[1,1];
VaThetaX=fsolve(@(x)KMVfun(EtoD,r,T,EquityTheta,x),x0);
Va=VaThetaX(1)*E;
AssetTheta=VaThetaX(2);
end

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 28 Oct 2017
Edited: John D'Errico on 28 Oct 2017
It is NEVER a good idea to start any optimization at zero. That may easily screw up the gradient estimation, in case the code uses a relative increment on the variables. A random starting point, when you don't have a good idea of a guess, is always safer. Best of course is to use a start point that is close to the result.
No need to use an m-file function here. A function handle is sufficient.
F = @(x) [(39*x(1)^2*x(2)^2)/100 - (x(2)^2)/5 - 2*x(1)^2 + 1;(39*x(1)^2*x(2)^2)/100 - (7*x(2)^2)/25 - (14*x(1)^2)/5 + 49/25];
[x,fval] = fsolve(F,rand(1,2))
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x =
0.795 2.3832
fval =
-8.908e-07
-1.0553e-06
  1 Comment
Bodhisatwa Goswami
Bodhisatwa Goswami on 28 Oct 2017
Thanks a lot for the prompt reply! That worked! Also thanks for the suggestions!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 28 Oct 2017
Use any starting point whose components have absolute value 1E-7 or higher (approximately).
There are 8 solutions to those equations and your starting point [0 0] is in the middle of all of them; the algorithm cannot figure out which direction to head (the algorithm does not make random choices.) Using a non-zero starting point places one of the solutions closer and allows it to be found.

Products

Community Treasure Hunt

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

Start Hunting!