Plot temperature distribution within a sphere for 1D conduction problem
Show older comments
Hey there!
I've developed a MATLAB code using the PDEPE tool to simulate 1D conduction within a sphere. My aim is to visualize the temperature distribution within the sphere over time. To achieve this, I've put together a script that calculates the radius using Cartesian coordinates (r = sqrt(x^2 + y^2)) and plots the corresponding temperature. The resulting 2D plot resembles a disk within a square, representing the sphere. While the code runs smoothly, I'm facing an issue with the visualization: I'd like to exclude coloring the outer parts of the sphere, which represent the surrounding air.
Any suggestions or any other simple way on how to achieve this would be greatly appreciated!
Cooling_Time = 5;
nodes_r = 201;
r = linspace(0,r0,nodes_r); % Sets space nodes
nodes_t = 1+Cooling_Time*360;
t = linspace(0,Cooling_Time*3600, nodes_t); % Sets time steps
x = linspace(-r0, r0, nodes_r);
y = linspace(-r0, r0, nodes_r);
T = pdepe(m, @Heatpde, @HeatIC, @HeatBC,x,t)
temperature = zeros(length(y), length(x));
figure
for k = 1:nodes_t
for i = 1:length(x)
for j = 1:length(y)
r_calcule = sqrt(x(i)^2 + y(j)^2);
indice_r = find(r <= r_calcule, 1, 'last');
if isempty(indice_r)
temperature(j, i) = 0;
else
temperature(j, i) = T(k,indice_r);
% temperature(j, i) = T(nodes_t,indice_r);
end
end
end
% Displaying the temperature contour
contourf(x, y, temperature, 'linecolor','k');
xlabel('x');
ylabel('y');
title('Temperature Contour');
colormap jet;
colorbar;
axis equal;
set(gca, 'FontName', 'LM Roman 10', 'TickDir', 'out', 'box', 'on');
pause(1e-7)
end

Accepted Answer
More Answers (0)
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!