- 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!