Index in position 2 exceeds array bounds. Index must not exceed 7. Error in ftcsimplicit (line 39) plot(x,u(:,7200),'-',x,u(:,14400),'-',x,u(:,21600),'-',x,u(:,28800),x,u(:,3
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% Chlorine decay using FTCS Implicit method
clear;
% Parameters to define the chlorine dacay in the pipe and the range in space and time
L= 5.; % Length of the pipe
T= 43200.; % Final time
% Parameters needed to fully solve the equation within the implicit method
maxk = 6; % Number of time steps
dt = T/maxk;
n = 50.; % Number of space steps
dx = L/n;
cond = 1. % Conductivity
b = cond*dt/(dx^2);
% Initial temperature of the wire: a sinus
for i = 1:n+1
x(i)= (i-1)*dx;
u(i,1) = sin(pi*x(i));
end
% Temperature at the boundary (T=0)
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k)=0.;
time(k) = (k-1)*dt;
end
aa(1:n-2)=-b;
bb(1:n-1)=1.+2.*b;
cc(1:n-2)= -b;
MM = inv(diag(bb,0)+diag(aa,-1)+diag(cc,1));
% Implementation of the implicit method
for k=2:maxk %Time loop
uu=u(2:n,k-1);
u(2:n,k)= MM*uu;
end
% Graphical representation of the temperature at different selected times
figure (1)
plot(x,u(:,7200),'-',x,u(:,14400),'-',x,u(:,21600),'-',x,u(:,28800),x,u(:,36000),x,u(:,43200),'-')
title('Temperature within the fully implicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the fully implicit method')
xlabel('X')
ylabel('Temperature')
2 commentaires
Mujtaba Farrukh
le 6 Avr 2022
Sir, varible "u" size is 51x7 means it has 7 columns (means you can only access 7 columns not more than that ) and in the line 39, you are extracting the columns 7200, 14400 and etc, which exceeds the index value of u's column. Hence results in error.
Mathieu NOE
le 6 Avr 2022
the plot time steps should be normalized by your dt = 7200 to make the plot work
plot(x,u(:,7200/dt),'-',x,u(:,14400/dt),'-',x,u(:,21600/dt),'-',x,u(:,28800/dt),x,u(:,36000/dt),x,u(:,43200/dt),'-')
Réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!