- 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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
ChrisR
el 29 de Oct. de 2021
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 comentarios
Bradley Davis
el 17 de Jun. de 2022
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035930/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035935/image.jpeg)
0 comentarios
Ver también
Categorías
Más información sobre Geometry and Mesh en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!