Temperature distribution with respect to time dependent

Hello, Everyone im little bit new to the coding im trying to plot a graph of temperature with respect to time in a water pipe im getting some error during inserting the formula:
dTdt(1:n)=((m*Cp*(T(0:n-1)-T(1:n))+qflux*2*pi*r*dx)/(rho*Cp*dx*pi*r^2)); could anyone help me with the right insertion.Here is the full code in the below and im getting a constant straight line during plotting that means the temperatures are not changing.
L=489; %mm,length of pipe
n=100;%number of simulation nodes
r=20; %mm pipe radius
m=3; %mass flow rate
Cp=1350; %J/kg*k specific heat
rho=1000; %kg/m3 density of water
pi=3.14159;
T0=298; %deg C,pipe fluid initial temp
Ti=313; %deg C, pipe temp
qflux=100000; %heat flux
tfinal=600; %simulation time
dt=0.1; %time step
dx=L/n; %node thickness
x=linspace(dx/2,L-(dx/2),n);
T=ones(n,1)*T0;
dTdt=zeros(n,1);
t=0:dt:tfinal;
for
j=1:length(t);
dTdt(1:n)=((m*Cp*(T(0:n-1)-T(1:n))+qflux*2*pi*r*dx)/(rho*Cp*dx*pi*r^2));
dTdt(0)=((m*Cp*(Ti-T(0))+qflux*2*pi*r*dx)/(rho*Cp*dx*pi*r^2));
T= T+dTdt*dt;
figure;
hold on;
plot(x,T);
axis([0 L 290 320])
pause(0.02);
end

2 Comments

There are a number of things wrong with your code. First, dTdt(0) tries to assign something to the 0th index of an array. Arrays must have positive indexes, so if you want it to be the first value, the index must be 1. Similar issues with T(0:n-1), you cant start from the 0th index of an array.
In addition, be very careful about using the figure command inside a for statement; every time the loop runs, a new figure is created. Remove that line immediately. Then try to post your question again, because what you have right now will not run.
Hello Jakob,Thank you for your reply .
Yes i already tried with 1 instead of 0 but im getting this error- nonconformant arguments (op1 is 99x1, op2 is 100x1).but im unable to find it.

Sign in to comment.

Answers (0)

Asked:

on 9 Dec 2019

Commented:

on 9 Dec 2019

Community Treasure Hunt

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

Start Hunting!