error message vectors must be the same length
Mostrar comentarios más antiguos
Hello, im trying to plot the temperature distribution vs time, I get the right temp answer from running the code but when i try to plot it vs time it gives me an error message saying that vectors must be the same length. The question is asking to plot the surface temperature as a function of time from 0 to 1800 seconds. Thank you.
clear
clc
close
L=0.2;
Ti=600;
Tinf=22;
h=240;
k=80.2;
alpha=3.31e-5;
dx=0.01;
dt=1.5;
Fo=(alpha*dt)/dx^2;
Bii=(h*dx)/k;
Bio=(h*dx)/k;
x=[0:dx:L];
n=length(x);
T=Ti*ones(1,n);
t=[0:dt:1800];
for k=2:length(t)
Tnew(1)=T(1)*(1-2*Fo-2*Bio*Fo)+2*Fo*T(2)+2*Bio*Fo*Tinf;
for i=2:n-1
Tnew(i)=T(i)*(1-2*Fo)+Fo*(T(i+1)+T(i-1));
end
Tnew(n)=T(n)*(1-2*Fo-2*Bii*Fo)+2*Fo*T(n-1)+2*Bii*Fo*Tinf;
T=Tnew;
end
Tnew(n)
plot(t,Tnew)
4 comentarios
salem alnaqbi
el 19 de Jul. de 2018
Rik
el 19 de Jul. de 2018
I think you got confused with your indexing. k is not used anywhere in your loop, so your loop does the same thing every time. I have no idea what your calculation should be, so I have no idea how it should be fixed. Your Tnew vector is 21 elements, while t is 1201.
salem alnaqbi
el 19 de Jul. de 2018
Guillaume
el 19 de Jul. de 2018
@Rik, "k is not used anywhere in your loop, so your loop does the same thing every time"
Actually, the k loop calculates a new T based in its value in the previous iteration, so there's no issue on that front.
I suspect that the intent of the code is to plot the values of T (== Tnew) at a given index for each k.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Numerical Integration and Differentiation 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!