errors in this code - 1D PDE with Boundary Condition
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i am trying to solve ade and getting errors. plz help.
K = 0.15;
D = 100;
U = 1;
dt = 0.005; dx = 1;
L = 10;
t = 50; T = 100;
c0 = 100; C0 = 100; %cin = 100mg/m^3
nx = 1+L/dx; nt = 1+t/dt;
c = zeros(nx,nt);
NT = 1+T/dt;
C = zeros(nx,NT);
c(1,:) = c0; C(1,:) = C0;
for k = 1:NT
CN = U*dt/dx;
DN = D*dt/dx^2;
C(1,k) = c0;
for i = 1:nx
if (i == 1)
C(i,k+1) = (2*DN)*c0+c(i,k+1)*(1-(2*DN)-(k*dt)-((DN-CN/2)*(2*dx*U/D)))+((DN-(CN/2)*(2*dx*c0*U/D)));
elseif (i == nx)
C(i,k+1) = 2*DN*c(i-1,k)+(1-2*DN-k*dt)*c(i,k);
else
C(i,k+1) = (DN+CN/2)*C(i-1,k) + (1-2*DN-K*dt)*C(i,k) +(DN-CN/2)*C(i+1,k);
end
end
end
x = [0:dx:L];
plot(x,C(:,NT),'b');
return
0 commentaires
Réponses (1)
Matt Tearle
le 19 Avr 2011
I don't know exactly what you're trying to do with t and T (and associated nt and NT), but the result is that c and C have different numbers of columns. Your calculation of C(i,k+1) depends on c(i,k), and k runs from 1 to NT. Given that NT > nt, you end up referencing columns of c that don't exist -- ie k gets to nt+1 and then referencing c(i,k) must fail.
Voir également
Catégories
En savoir plus sur Boundary Conditions 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!