- 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').
- If you change the plot statement as in comment #1, then add "hold on". Otherwise, you will see only the last point.
- 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?
how to plot a temperature distribution of a solid cylinder with heat generation
26 次查看(过去 30 天)
显示 更早的评论
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')
end
xlabel('r','fontsize',15)
ylabel('Tr','fontsize',15)
title('Part 1: Original Temperature Distribution','fontsize',20)
0 个评论
回答(2 个)
ChrisR
2021-10-29
Kailey,
Here are a few comments:
Another approach is to write
r = 0:0.01:r0;
for i = 1:length(r)
Tr(i) = ...
end
plot(r,Tr)
The equation for Tr will likely depend on the radius r(i).
0 个评论
Bradley Davis
2022-6-17
I tried this, and got a nice plot:
% establish a radius array from core to surface
r_d = linspace(r0,rs,100);
% Preallocate an array for the temperature distribution at r
t_rad = zeros(size(r_d));
% Loop through r and solve for temperature
for i = 1:length(t_rad)
% The incremental radial change matters, hence (r_d(i) - r0)^2
t_rad(i) = ((-p_vol * ((r_d(i)-r0)^2))/(4*k)) + tsurf + ((p_vol * (rs^2))/(4*k));
plot(i,t_rad(i),'bo')
hold on
end
% create second plot for comparison
figure(2)
plot(r_d,t_rad)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Heat and Mass Transfer 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!