Question: Heat diffusion on a rod over the time In class we learned analytical solution of 1-D heat equation Below is the MATLAB code which simulates

Heat diffusion on a rod over the time

In class we learned analytical solution of 1-D heat equation

Below is the MATLAB code which simulates finite difference method to solve the above 1-D heat equation.

%1-D Heat equation

%example 1 at page 782

%lambdat=c.k/h^2

%T(x,t)=temperature along the rod

%by finite difference method

%(T(x,t+dt)-T(x,t))/dt = (T(x+dx,t)-2T(x,t)+T(x-dx,t))/dx^2

%solve for T(x,t+dt) by iteration

%heat constant

closeall

clearall

c=1;

L=1%length of the rod

N=5%# of elements

%dicretize Xspace

h=L/N;

x_vec=0:h:L;

%discretize time

T=0.5;

M=50;

k=T/M;

t_vec=0:k:T;

%temperature matrix

T_mat=zeros(length(x_vec),length(t_vec));

%boundary conditions

T_mat(1,:)=0;

T_mat(end,:)=0;

%initial conditions

T_mat(:,1)= sin(pi.*x_vec);

[tt,xx]=meshgrid(t_vec,x_vec);

subplot(2,1,1);

mesh(xx,tt,T_mat);

title('Analytical vs numerical in 3D');

T_mat_calc=zeros(length(x_vec),length(t_vec));

T_mat_calc(:,1)= sin(pi.*x_vec);

lamda=(c*k/(h^2));

for tdx=1:length(t_vec)-1

for idx=2:length(x_vec)-1

T_mat(idx,tdx+1)=T_mat(idx,tdx)+lamda*((T_mat(idx+1,tdx)-2*T_mat(idx,tdx)+T_mat(idx-1,tdx)));

T_mat_calc(idx,tdx+1)= (exp((-pi^2)*(t_vec(tdx+1))))*sin(pi*(x_vec(idx)));

end

end

%plot

subplot(2,1,2)

[tt,xx]=meshgrid(t_vec,x_vec);

mesh(xx,tt,T_mat);

figure

plot(x_vec,T_mat(:,1),x_vec,T_mat(:,11),x_vec,T_mat(:,21),x_vec,T_mat(:,31),x_vec,T_mat(:,41),x_vec,T_mat(:,51));

xlabel('Rod length (m)'); ylabel('Temperature (C)');

legend('Initially','At t=0.1sec','At t=0.2 secs','At t=0.3 secs',' At t=0.4 secs',' At t=0.5 secs');

title('Numerical Solution');

figure

plot(x_vec,T_mat_calc(:,1),x_vec,T_mat_calc(:,11),x_vec,T_mat_calc(:,21),x_vec,T_mat_calc(:,31),x_vec,T_mat_calc(:,41),x_vec,T_mat_calc(:,51));

xlabel('Rod length (m)'); ylabel('Temperature (C)');

legend('Initially','At t=0.1sec','At t=0.2 secs','At t=0.3 secs',' At t=0.4 secs',' At t=0.5 secs');

title('Analytical Solution');

Copy and paste the above code in the MATLAB editor and run in the MATLAB. Look at how temperature changes at the times indicated in the graph.

  • What is the initial condition for the temperature on this rod?
  • What are the boundary conditions?
  • Analytical Solution: Hand calculate the solution by using separation of variables and include in your submitted homework. You will use heat equation solution from chapter 13. You must insert the analytical solution into the code above.
  • Do you expect to see the heat diffusing the way you see in the graph? Justify your answer by comparing analytical solution with numerical solution.

Submit your typed or printed answers to the above questions and plot and submit analytical solution and numerical solutions and your code. (In the code T_mat matrix is the numerical solution)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mechanical Engineering Questions!