plotting with for loop
Mostrar comentarios más antiguos
hello I am trying to solve FTCS discretization of the heat equation
and I have writtenn the below code:
I have 3 grid refinement, dx=[0.5,0.25,0.05];
I am going to plot 3 plot get for each grid (x,T1) in one plot. Currently, I can not plot 3 plot in one plot. I do not know how pull out T1 values after completion in for loop. Can someone tell me how to plot?
%setting up the parameters
clear;clc;;close all;
U0=2;
dt=0.01;
tf=1000;
ntotal=tf/dt;
dx=[0.5,0.25,0.05];
Kappa=0.001;
% boundary condition
for i=1:length(dx)
x = (-3:dx(i):3);
n=length (x);
alpha=Kappa*dt./dx(i).^2;
for j=1:n
if (1<x(j)) || (x(j)<-1)
T0(j)=0;
else T0(j)=U0;
end
end
%solving the problem with FTC
for k=1:ntotal
for i=2:n-1
T1(i) = T0(i) + alpha*(T0(i+1)-2*T0(i)+T0(i-1));
T1(1)=T0(1) + alpha*(T0(2)-2*T0(1)+0);
T1(n) = T0(n) + alpha*(0-2*T0(n)+T0(n-1));
end
T0=T1;
end
figure
plot (x,T1)
hold on
end
3 comentarios
Nima Vali
el 28 de Sept. de 2020
Star Strider
el 28 de Sept. de 2020
As always, my pleasure!
Nima Vali
el 28 de Sept. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Crystals en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!