Solving non linear system of equations
7 views (last 30 days)
Show older comments
Hello!I have some troubles while solving the non-linear system.
http://saveimg.ru/show-image.php?id=19f0894034eb37dc9fef4a7a088c2a55 this is a link to my system, which I need to solve against V and sigma_v
I wrote the following code in mm-file
function y = mm(x,D,r,delta_t,S,sigma_s)
d1=(log(x(2)/D)+(r-0.5*x(1)*x(1)*delta_t))/(x(1)*sqrt(delta_t));
d2=d1-x(1)*sqrt(delta_t);
y=((sigma_s*S-normcdf(d1,0,1)*x(1)*x(2))^2+(S-x(2)*normcdf(d1,0,1)-D*exp(-r*delta_t)*normcdf(d2,0,1))^2);
and I use the following command:
x=fminsearch('mm(x,5000000,0.0071,2548,74513269760,0.000665992)',[10 0.0001])
but the answer is 10 0.00001 which is not correct
So I'd be glad if someone shows me a mistake, which I made
Thx in advance!
0 Comments
Answers (2)
Teja Muppirala
on 7 May 2011
Wow. Now this is really like finding a needle in a haystack.
But FMINSEARCH can find it if you just give it a better starting condition, and enough function evaluations:
opts = optimset('tolfun',0,'tolx',0,'maxfun',Inf,'display','iter');
xmin = fminsearch(@(x)mm(x,5000000,0.0071,2548,74513269760,0.000665992),[0.0001 1e10],opts)
This gives you the answer:
xmin(1) = 6.659920000005961e-004
xmin(2) = 7.451326975993047e+010
The difficulty was in finding a good initial condition. How did I do it? By making a giant plot over logarthmic space:
jvec = linspace(-10,20,201);
kvec = linspace(-10,20,201);
A = zeros(numel(jvec),numel(kvec));
for jj = 1:numel(jvec)
for kk = 1:numel(kvec)
A(jj,kk) = mm(10.^[jvec(jj) kvec(kk)],5000000,0.0071,2548,74513269760,0.000665992);
end
end
figure
imagesc(kvec,jvec,log10(A)); colorbar;
0 Comments
terance
on 7 May 2011
1 Comment
Teja Muppirala
on 7 May 2011
Your results are the same as mine. This is just a difference in how many digits are displayed. If you do
format long
and then view the result, it is the same. Also, because the numbers are very differently scaled, it helps to view them one at a time
xmin(1)
xmin(2)
On the plot, red means high and blue means low, just as the colorbar indicates. I just looked for where there were blue areas (and actually I replotted that graph several times, changing the limits and zooming in a little each time until I was pretty certain where a good initial condition was).
See Also
Categories
Find more on Time and Frequency Domain Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!