Implementation of Newton's Method with the function representation that depends on iteration number
Show older comments
Hello everyone in Matlab community ! I have been fighting with my problem for last year and now I think it is impossible to implement what I need it to do in Matlab. My problem is that I need to implement Newton-Raphson algorithm with help of two function Funk and Funkder (the functions are presented below ).I have no problem with that, however the biggest issue is that those two functions depend on number of iteration in Newton algorithm. I wonder if there is any way to submit number of iteration as a part of variable in the mentioned function . I would appreciate any hint , any advice, suggestion ! Thanks in advance, with all respect, Deemitry .
This is Newton method implementation :
M=10;
w=M;
n=ones(M,1);
S0 = 40; K = 45; r = 0.01; T =6/12;
sigma = 0.3;
delta=0.1;
eps=0.000000001;
counter=1;
n(M)=(K*min(1,r/delta));
while (abs(Funk(n))>eps)
if (w>1)
n(w-1)=n(w)-(Funk(n)/Funkder(n))
w=w-1;
else
break
end
end
And here comes two functions:
function [o]=Funk(x1)
M=10;
S0 = 40; K = 45; r = 0.01; T =6/12;
sigma = 0.3;
delta=0.1;
delT=T/M;
x(M)=(K*min(1,r/delta));
i=8;
if (i+1)<(M-1)
for j=(i+1):1:(M-1)
fsum(j)=delT.*f1(x1(i),x1(j),(j-i)*delT);
end
summa1=sum(fsum);
else
for j= (M-1):1:(i+1)
fsum(j)=delT.*f1(x1(i),x1(j),(j-i)*delT);
end
summa1=sum(fsum(j));
end
%end
o=x1(i)-K+p(x1(i),K,(M-i)*delT)+0.5*delT*(f1(x1(i),x(M),(M-i)*delT)+0.5*(r*K-delta*x1(i)))+summa1;
if~nargout;
o;
end
end
function [l]=Funkder(x3)
S0 = 40; K = 45; r = 0.01; T =6/12;
sigma = 0.3;
delta=0.1;
M=10;
delT=T/M;
i=8;
if (i+1)<(M-1)
for j=(i+1):1:(M-1)
Fsum1(j)=exp(-delta*(j-i)*delT)*(c((log(x3(i)/x3(j))+(r-delta+(sigma^2)/2)*(j-i)*delT)/(sigma*(((j-i)*0.5)^0.5)))*(delta-(r*K)/x3(j))-delta*normcdf(-(log(x3(i)/x3(j))+(r-delta+(sigma^2)/2)*(j-i)*delT)));
end
summa=sum(Fsum1)
else
for j= (M-1):1:(i+1)
Fsum1(j)=exp(-delta*(j-i)*delT)*(c((log(x3(i)/x3(j))+(r-delta+(sigma^2)/2)*(j-i)*delT)/(sigma*(((j-i)*0.5)^0.5)))*(delta-(r*K)/x3(j))-delta*normcdf(-(log(x3(i)/x3(j))+(r-delta+(sigma^2)/2)*(j-i)*delT)));
end
summa=sum(Fsum1);
end
l=1-exp(-delta*(M-i)*delT)*normcdf(-(log(x3(i)/K)+(r-delta+(sigma^2)/2)*(j-i)*delT))+delT*summa;
if~nargout;
l;
end
end
Accepted Answer
More Answers (1)
Dimitry
on 25 Mar 2011
Categories
Find more on Symbolic Math Toolbox 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!