how to fix "limits are too large error" while running a transformed black-Scholes equation into a heat equation using the explicit method ?....
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bob Thompson
2018-6-18
编辑:Bob Thompson
2018-6-18
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Thermal Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!