"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lmlcf3$a9g$1@newscl01ah.mathworks.com>...
> If people in the group need to read through pages and pages of code to try
> to help you, they're likely to move on to the next post, one that doesn't
> require them to read that much. If they need to read up to about 20 lines of
> code, they're more likely to read it and offer some guidance.
oh i see, so sorry i thought i should paste all of them cause the first section is needed
> Be careful with HOLD. If you're trying to plot two or three lines on the
> same axes, you're probably fine. If you end up trying to plot several
> _dozen_ lines, you may see some slowdown. Several _hundred_ lines is going
> to slow you down. I've seen people (some of whom shall remain nameless)
> accidentally do this then wonder why their machines are running v-e-r-y
> slowly when they bring up the figure window.
yes i think you're right it really make my machines running very slowly, ok i'll try look on it again
> One more suggestion: DON'T start multiple threads for the same question.
> Someone may offer a solution in one of the threads that's already been
> offered in another, and that's just a waste of time.
again, I'm sorry for starting new threads, I try to make them to simple question by giving my code on link, and i have another problems. in my last thread
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
maybe like this,
I should change the range from imax+1,and jmax+1 to imax-1,jmax-1, to discover the values in the interior of matrix, i've try to modified it on these lines but still not work
here some variable that affect of the changes
================
Vmaks=max(V);
Vmin=min(V);
PMax=2*(Vmaks);
================
p=(PMax-Vmin)/(imax);
w=(T-tmin)/(jmax);
VV=Vmin:p:PMax;
maxwa=max(VV-D(tr),0);
F{tr}=maxwa(1:size(maxwa,2))'; %maturity values upper boundary prices (t=T..0) (:,1)
F2{tr}=F{tr};
F3{tr}=F{tr};
================
for i=1:jmax+1
t(i)=(i-1)*w;
tau(i)=T-t(i);
end
================
D1=diag(1:1:(imax-1));
D2=D1.^2;
T1=diag(ones(imax-2,1),1)-diag(ones(imax-2,1),-1);
T2=-2*eye(imax-1,imax-1)+diag(ones(imax-2,1),1)+diag(ones(imax-2,1),-1);
=================
rd=r-d;
A{tr}=((1-(r*w))*eye(imax-1))+(0.5*w*sig2(tr)*D2*T2)+(0.5*w*rd*D1*T1); %FTCS
g{tr}=[(0.5*w*(sig2(tr)-rd))*(max(Vmin-D(tr)*exp((-r)*tau),0)) zeros(1,(imax-3)) (0.5*w*(imax-1)*(sig2(tr)*(imax-1)+rd))*max(PMax-(D(tr)*exp((-r)*tau)),0)]'; %complete the FTCS
B{tr}=((1+(r*w))*eye(imax-1))+(0.5*w*sig2(tr)*D2*T2)+(0.5*w*rd*D1*T1); %BTCS
u{tr}=[(0.5*w*(sig2(tr)-rd))*(max(Vmin-D(tr)*exp((-r)*tau),0)) zeros(1,imax-3) (0.5*w*(imax+1)*(sig2(tr)*(imax+1)+rd))*max(PMax-(D(tr)*exp((-r)*tau)),0)]'; %complete the BTCS
invB{tr}=inv(B{tr});
invIB{tr}=inv(eye(imax-1)+B{tr});
===================
MatrixIterF{tr,1}=NaN(imax+1,jmax+1);
MatrixIterF{tr,1}(1,:)=max(Vmin-(D(tr)*exp((-r)*tau)),0); %lowest boundary (1,:)
MatrixIterF{tr,1}(imax+1,:)=max(PMax-(D(tr)*exp((-r)*tau)),0);%upper boundary (:,imax+1)
MatrixIterF{tr,1}(:,1)=F{tr}; %initial condition, maturity value
(will be same for MatrixIterF{tr,2} and MatrixIterF{tr,3}
====================
for j=2:jmax+1
F{tr}=A{tr}*F{tr}+g{tr}; %FTCS
F2{tr}=invB{tr}*(F2{tr}+u{tr}); %BTCS
F3{tr}=invIB{tr}*((A{tr}+eye(imax-1))*F3{tr}+g{tr}+u{tr}); %Crank-Nicolson
for i=1:imax
if F{tr}(i)>=(maxwa(i))'
MatrixIterF{tr,1}(i,j)=F{tr}(i);
else
MatrixIterF{tr,1}(i,j)=(maxwa(i))';
end
(will be the same for F{tr,2} and F{tr,3}
F{tr}=MatrixIterF{tr,1}(1:imax+1,j);
F2{tr}=MatrixIterF{tr,2}(1:imax+1,j);
F3{tr}=MatrixIterF{tr,3}(1:imax+1,j);
end
=======================
MatrixIterWait{tr,1}=NaN(imax+1,jmax+1);
MatrixIterWait{tr,2}=NaN(imax+1,jmax+1);
MatrixIterWait{tr,3}=NaN(imax+1,jmax+1);
for j=1:jmax+1
for i=1:imax+1
MatrixIterWait{tr,1}(i,j)=MatrixIterF{tr,1}(i,j)-(maxwa(i))'; %FTCS
MatrixIterWait{tr,2}(i,j)=MatrixIterF{tr,2}(i,j)-(maxwa(i))'; %BTCS
MatrixIterWait{tr,3}(i,j)=MatrixIterF{tr,3}(i,j)-(maxwa(i))'; %C-N
end
end
=========================
dimension mismatch since i change the range, i used to prepare empty matrix with size (imax+1, and jmax+1) and the (1,:),(imax+1,:),(:,1) part will be filled with boundary, and the interior will be filled by the result of calculation.
> If people in the group need to read through pages and pages of code to try
> to help you, they're likely to move on to the next post, one that doesn't
> require them to read that much. If they need to read up to about 20 lines of
> code, they're more likely to read it and offer some guidance.
oh i see, so sorry i thought i should paste all of them cause the first section is needed
> Be careful with HOLD. If you're trying to plot two or three lines on the
> same axes, you're probably fine. If you end up trying to plot several
> _dozen_ lines, you may see some slowdown. Several _hundred_ lines is going
> to slow you down. I've seen people (some of whom shall remain nameless)
> accidentally do this then wonder why their machines are running v-e-r-y
> slowly when they bring up the figure window.
yes i think you're right it really make my machines running very slowly, ok i'll try look on it again
> One more suggestion: DON'T start multiple threads for the same question.
> Someone may offer a solution in one of the threads that's already been
> offered in another, and that's just a waste of time.
again, I'm sorry for starting new threads, I try to make them to simple question by giving my code on link, and i have another problems. in my last thread
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
maybe like this,
I should change the range from imax+1,and jmax+1 to imax-1,jmax-1, to discover the values in the interior of matrix, i've try to modified it on these lines but still not work
here some variable that affect of the changes
================
Vmaks=max(V);
Vmin=min(V);
PMax=2*(Vmaks);
================
p=(PMax-Vmin)/(imax);
w=(T-tmin)/(jmax);
VV=Vmin:p:PMax;
maxwa=max(VV-D(tr),0);
F{tr}=maxwa(1:size(maxwa,2))'; %maturity values upper boundary prices (t=T..0) (:,1)
F2{tr}=F{tr};
F3{tr}=F{tr};
================
for i=1:jmax+1
t(i)=(i-1)*w;
tau(i)=T-t(i);
end
================
D1=diag(1:1:(imax-1));
D2=D1.^2;
T1=diag(ones(imax-2,1),1)-diag(ones(imax-2,1),-1);
T2=-2*eye(imax-1,imax-1)+diag(ones(imax-2,1),1)+diag(ones(imax-2,1),-1);
=================
rd=r-d;
A{tr}=((1-(r*w))*eye(imax-1))+(0.5*w*sig2(tr)*D2*T2)+(0.5*w*rd*D1*T1); %FTCS
g{tr}=[(0.5*w*(sig2(tr)-rd))*(max(Vmin-D(tr)*exp((-r)*tau),0)) zeros(1,(imax-3)) (0.5*w*(imax-1)*(sig2(tr)*(imax-1)+rd))*max(PMax-(D(tr)*exp((-r)*tau)),0)]'; %complete the FTCS
B{tr}=((1+(r*w))*eye(imax-1))+(0.5*w*sig2(tr)*D2*T2)+(0.5*w*rd*D1*T1); %BTCS
u{tr}=[(0.5*w*(sig2(tr)-rd))*(max(Vmin-D(tr)*exp((-r)*tau),0)) zeros(1,imax-3) (0.5*w*(imax+1)*(sig2(tr)*(imax+1)+rd))*max(PMax-(D(tr)*exp((-r)*tau)),0)]'; %complete the BTCS
invB{tr}=inv(B{tr});
invIB{tr}=inv(eye(imax-1)+B{tr});
===================
MatrixIterF{tr,1}=NaN(imax+1,jmax+1);
MatrixIterF{tr,1}(1,:)=max(Vmin-(D(tr)*exp((-r)*tau)),0); %lowest boundary (1,:)
MatrixIterF{tr,1}(imax+1,:)=max(PMax-(D(tr)*exp((-r)*tau)),0);%upper boundary (:,imax+1)
MatrixIterF{tr,1}(:,1)=F{tr}; %initial condition, maturity value
(will be same for MatrixIterF{tr,2} and MatrixIterF{tr,3}
====================
for j=2:jmax+1
F{tr}=A{tr}*F{tr}+g{tr}; %FTCS
F2{tr}=invB{tr}*(F2{tr}+u{tr}); %BTCS
F3{tr}=invIB{tr}*((A{tr}+eye(imax-1))*F3{tr}+g{tr}+u{tr}); %Crank-Nicolson
for i=1:imax
if F{tr}(i)>=(maxwa(i))'
MatrixIterF{tr,1}(i,j)=F{tr}(i);
else
MatrixIterF{tr,1}(i,j)=(maxwa(i))';
end
(will be the same for F{tr,2} and F{tr,3}
F{tr}=MatrixIterF{tr,1}(1:imax+1,j);
F2{tr}=MatrixIterF{tr,2}(1:imax+1,j);
F3{tr}=MatrixIterF{tr,3}(1:imax+1,j);
end
=======================
MatrixIterWait{tr,1}=NaN(imax+1,jmax+1);
MatrixIterWait{tr,2}=NaN(imax+1,jmax+1);
MatrixIterWait{tr,3}=NaN(imax+1,jmax+1);
for j=1:jmax+1
for i=1:imax+1
MatrixIterWait{tr,1}(i,j)=MatrixIterF{tr,1}(i,j)-(maxwa(i))'; %FTCS
MatrixIterWait{tr,2}(i,j)=MatrixIterF{tr,2}(i,j)-(maxwa(i))'; %BTCS
MatrixIterWait{tr,3}(i,j)=MatrixIterF{tr,3}(i,j)-(maxwa(i))'; %C-N
end
end
=========================
dimension mismatch since i change the range, i used to prepare empty matrix with size (imax+1, and jmax+1) and the (1,:),(imax+1,:),(:,1) part will be filled with boundary, and the interior will be filled by the result of calculation.