how to plot a temperature distribution of a solid cylinder with heat generation

32 views (last 30 days)
Kailey lewis
Kailey lewis on 28 Oct 2021
Answered: ChrisR on 29 Oct 2021
so I am trying to plot the temperature distribution of a solid cylinder with heat generation in MATLAB. I have to use a for loop as per insctrutions of the assignment. I wrote this code based on the given information and hand calculated equations for the the surface temperature (Ts) and temperature destribution equation (Tr). The code is outputting a graph but its not graphing anything its just blank. Anyone know how to get it to plot the temperature distribution?
my code:
format long
Ti = 20; %temp infinity (C)
h = 75; %convection coeff (w/m2k)
q_g = 1200; %heat gen (w/m3)
k = 5.2; %thermal conduc (w/mk)
r0 = 0.1; %surfaceradius (m)
r1 = 0; %center (m)
Ts = Ti+((q_g*r0)/(2*h));
for i=0:0.01:r0
Tr = ((-q_g*(r1^2))/(4*k))+Ts+((q_g*(r0^2))/(4*k));
plot (i,Tr,'b')
title('Part 1: Original Temperature Distribution','fontsize',20)

Answers (1)

ChrisR on 29 Oct 2021
Here are a few comments:
  1. You are plotting one point at a time, but with that plot statement, you won't see any points. You could try plot(i,Tr,'bo').
  2. If you change the plot statement as in comment #1, then add "hold on". Otherwise, you will see only the last point.
  3. Your calculation of Tr does not depend on i. That means it will keep producing the same value (21.3769). Should the radius be involved in your calculation?
Another approach is to write
r = 0:0.01:r0;
for i = 1:length(r)
Tr(i) = ...
The equation for Tr will likely depend on the radius r(i).

Community Treasure Hunt

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

Start Hunting!

Translated by