Scaling and centering a complicate equation

조회 수: 8 (최근 30일)
Clemens
Clemens 2014년 8월 10일
답변: Alan Weiss 2014년 8월 11일
Hi,
I have a somehow complicate equation in my matlab code which I try to solve by fsolve. I read a lot about some troubles with fsolve as long as the equation is not centered and rightly scaled.
Now, my equation is not that simple and therefore scaling and centering is a real challenge for me:
r = 0.046
p = 0.6760;
normk = 1.0804
y1 = 0.88;
y2 = 0.88;
Oz = 10000;
gamma = (y2/(1-y2))*(r+0.5*(normk^2))*T+0.5*((y2/(1-y2))^2)*(normk^2)*T;
%solve problem
d1e = @(y) (log((p/y))+(r-0.5*(normk^2))*(T))/(normk*sqrt(T));
d2e = @(y) d1e(y) + (normk*sqrt(T))/(1-y2);
WO0 = @(y) Oz*exp(-r*(T))*normcdf(d1e(y))+(((B*y2)/y)^(1/(1-y2)))*exp(gamma) *normcdf(d2e(y)) - Oz;
options = optimoptions('fsolve','TolX',1e-20,'TolFun',1e-20,'Display','iter','MaxFunEvals',10000000,'MaxIter',10000000);
[y,fval] = fsolve(WO0,1,options)
As you can see, I solve for y and the equation is not linear. The problem for centering is especially the normcdf. Has anyone got an idea? I appreciate every bit of input :)
Thank you.

답변 (1개)

Alan Weiss
Alan Weiss 2014년 8월 11일
  1. If y is scalar, then you should be using fzero, not fsolve.
  2. If you use fsolve, use optimset and not optiimoptions for your options.
  3. Do not set TolX and TolFun to values less than about 1e-14 (see Tolerances and Stopping Criteria).
  4. I suggest that you plot your function. You might get an idea of where the root is, and can center the function around that point.
  5. If your root is near where normcdf is near 1, then for more accuracy you might want to reformulate your computations to use normcdf(_,'upper').
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by