Implementation of Newton's Method with the function representation that depends on iteration number
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!