Error using surf: Data dimensions must agree
Mostra commenti meno recenti
I'm trying to create a surface plot to illustrate the second order Greek, Vera. I have wrote the following function for Vera:
function [Vera] = VERAmodifiedBS(S0,X,T,t,vol,r_base,r_quote)
d1=(log(S0./X)+(((r_base-r_quote)+((vol).^ 2./2)).*(T-t)))/(vol.*sqrt(T-t));
Ndash_d1=normpdf(d1);
Vera=(T-t).*S0.*exp(-r_quote.*(T-t)).*Ndash_d1;
end
This seems to be working fine however I get an error every time I try to plot it. Here is part of my script:
r_baseMAX=0.2;
volMAX=0.5;
r_base = (0:0.001:r_baseMAX);
vol = (0:0.02:volMAX);
[r_base,vol] = meshgrid (r_base, vol);
Vera=VERAmodifiedBS(S0,X,T,t,vol,r_base,r_quote);
figure
surf(r_base,vol,Vera);
S0, X, T being > 0 and t = 0. r_quote is an interest rate of 0.01. Looking in the workspace, r_base is a 26x201 double, vol is the same but Vera is a 26x25 double. I have no idea what could be causing the issue as I have what is essentially the exact same script for Rho and I've never had an issue with it. Any ideas?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!