![Screen Shot 2018-12-07 at 11.40.00 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198515/Screen%20Shot%202018-12-07%20at%2011.40.00%20PM.png)
Matrix dimension must agree problem
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Asir Tushar
el 7 de Dic. de 2018
Comentada: Asir Tushar
el 8 de Dic. de 2018
I have run the code on octave which gives the following plot.
When I tried the same code on Matlab , there was a dimension mismatch on line starting with "d1" . I think this is because of broadcasting. Anyone knows how to fix it ?
m=6;
n=61;
S0=70;
S1=130;
K=100;
r=.12;
T=1.0;
sigma=0.10;
time=transpose(linspace(T,0,m))
S=linspace(S0,S1,n);
d1=(log(S/K)+(( r + (sigma.^2)/2)*(T-time)))./(sigma*sqrt(T - time)); %(problem in this line)
d2=(log(S/K)+(( r - (sigma.^2)/2)*(T-time)))./(sigma *sqrt(T - time));
part1=bsxfun ( @times , normcdf ( d1 ) , S ) ;
part2=bsxfun ( @times , K *exp( - r *( T - time ) ) , normcdf ( d2 ) ) ;
VC = part1 - part2
plot(S,VC)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198514/image.png)
0 comentarios
Respuesta aceptada
madhan ravi
el 7 de Dic. de 2018
To be honest I didn't get any errors,
Try clear all at the very beginning of your code and try again.
![Screen Shot 2018-12-07 at 11.40.00 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198515/Screen%20Shot%202018-12-07%20at%2011.40.00%20PM.png)
3 comentarios
madhan ravi
el 8 de Dic. de 2018
Editada: madhan ravi
el 8 de Dic. de 2018
2018b you? post the complete error message you get everything in red , alright turns out that you are using version prior to 2016b so use bsxfun() with rdivide for ./ and times for * appropriately.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!