|
"Hugh " <h_a_patience@hotmail.com> wrote in message <ib1crc$6ep$1@fred.mathworks.com>...
> [code]
>
> function U= sabrCall(S,K,sig,r,T,nu,beta,rho,Smax,dS,Numax,dnu,dt,greek)
>
> if nargin < 14, greek =1;end
>
> NS=round(1/dS);
> dS=1/NS;
> Nnu=round(1/dnu);
> dnu=1/Nnu;
> Nt=round(T/dt);
> dt=T/Nt;
>
> Layers=zeros(2,NS+1,Nnu+1);
>
> tpast=1;
> tnow=2;
>
> Svalue=0:dS:Smax;
> Vvalue=0:dnu:Numax;
>
> payoff=max(Svalue-K,0);
> Layers(tpast,:,:)=payoff'*ones(1,Nnu+1);
>
> [S,VOL]= meshgrid(0:dS:Smax,0:dnu:Numax);
>
> Layers(tpast,1:NS,1:Nnu)=max(vetS-K,0);
>
> U =1;
> end
>
> [/code]
>
> The line Layers(tpast,:,:)=payoff'*ones(1,Nnu+1);
>
> is coming back as a dimensions mismatch but I don't see why? Moreover when I try to run the program with stops nothing shows in the workspace? Why is this?? It makes it alot harder to debug.
- - - - - - - - - -
In the assignment that is giving you errors
Layers(tpast,:,:)=payoff'*ones(1,Nnu+1)
the left side is 1 by NS+1 by Nnu+1 in size while the right side is n by Nnu+1 where n is the number of elements in 0:dS:Smax. If Smax is other than 1, then clearly n will differ from NS+1. However because of round off error, you might find cases where there is a difference even when Smax is exactly 1. This latter is because the assignment dS = 1/NS cannot be calculated exactly in general.
Roger Stafford
|