how to fix "limits are too large error" while running a transformed black-Scholes equation into a heat equation using the explicit method ?....
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I am trying to run an explicit heat equation . This is the prompt I am trying to solve:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191309/image.png)
My code works for certain items of an array but not for others as i am getting a limits are too large error.
This is from the following transformation:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191310/image.png)
My code below is:
S0 = 10:10:100;
K = 50;
r = .05;
T = 2;
sigma = .2;
price = blsprice(S0,K,r,T,sigma)
amax = 10;
amin = -10;
M = [10 100 200 400 800];
N = [10 100 200 400 800];
for k = 1:5
dx = (amax - amin)/(M(k)-1);
dt = T/(N(k)-1);
v = zeros(M(k), N(k));
r= dt/dx^2;
j = r/.5*sigma;
x = linspace(amin,amax,M(k));
v(:,1) = max(exp(.5*(j+1)*x) - exp(.5*(j-1)*x),0);
for n = 2:N(k)
%2 lines below are initial and boundary conditions
v(1,n) = v(1, 1);
v(N(k),n) = v(M(k),1);
%line below is explicit method discretized
v(2:M(k)-1,n) = (1-2*r)*v(2:M(k)-1,n-1)+r*v(1:M(k)-2,n-1)+r*v(3:M(k),n-1);
end
approx = v(2:M(k)-1,n)
end
error = abs(approx - price)
B= table(approx')
G=table(price')
surf(v)
I wanted to see if anybody had done anything close to this or can help on what I have so far. I am trying to understand if the prompt is erroneous or if my boundary conditions are wrong. Thank you
1 commentaire
Bob Thompson
le 18 Juin 2018
Modifié(e) : Bob Thompson
le 18 Juin 2018
Could you post the entire error message, including which line of your code triggers it, please?
Also, duplicate of https://www.mathworks.com/matlabcentral/answers/406030-how-to-fix-limits-are-too-large-on-heat-equation. Please remove one post.
Réponses (0)
Voir également
Catégories
En savoir plus sur Thermal Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!