Borrar filtros
Borrar filtros

how to fix limits are too large on heat equation

8 visualizaciones (últimos 30 días)
Janvier Solaris
Janvier Solaris el 17 de Jun. de 2018
Respondida: Walter Roberson el 19 de Jun. de 2018
Hi, I am trying to run an explicit heat equation . This is the prompt I am trying to solve:
My code below
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 get limits are too large error Any advice?
  5 comentarios
Janvier Solaris
Janvier Solaris el 19 de Jun. de 2018
thank you Greg have corrected it continuing to work on it to fix the other problems
Greg
Greg el 19 de Jun. de 2018
@Bob Nbob: I ran his code (a rare case of copy-paste actually works from a post, way to go Janvier!) and surprisingly, "Limits are too large" x2 is the entire error message.
@Janvier: Digging in, the error is coming from surf(v), and probably because much of v is NaN & Inf. I am guessing you are having a mix of initial/boundary conditions and indexing issues. Without knowledge of your field, I can't help identify where/what.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Jun. de 2018
Your v values are generating +inf and -inf because of the exp() and the fact that j gets large.
Then surf() is complaining because you are trying to plot data with such a large range. Although it will skip the +inf and -inf data, you also have data in the +/- 1E308 range. Historically, plots could not be done if the difference between the min and max exceed the capacity of single()

Categorías

Más información sobre Chemistry en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by