Effacer les filtres
Effacer les filtres

2D Temperature Distribution

1 vue (au cours des 30 derniers jours)
Jonathan Bird
Jonathan Bird le 18 Fév 2020
Commenté : darova le 21 Fév 2020
I need to plot the temperature distribution for the square cross-section of a bar, 3 sides are fixed at a temperature of 283 K, the fourth side at 508 K and the initial temperature of the interior is 307 K everwhere. The analytical solution is as follows:
L and W are both equal to 1, and the summation is done from n =1 to n =100. Here is what I have done so far, I've tried to make 100 10 x 10 grids and populate each element with values for theta and then sum all the grids to give a final 10 x 10 grid for the temperature distribution. I don't really understand how to execute this with for loops, thanks for any help.
X = 10;
Y = 10;
theta1 = zeros (X,Y);
for n =1:100
for X1 = 1:X
for Y1 = 1:Y
theta1(n,X1,Y1)=(2/pi)*(((-1)^(n+1)+1)/(n))*sin(n*pi*X1/L)*(sinh(n*pi*Y1/L))/(sinh(n*pi*W/L));
end
end
end
theta1sum = sum(theta1);
  1 commentaire
darova
darova le 18 Fév 2020
I found a mistake

Connectez-vous pour commenter.

Réponse acceptée

darova
darova le 18 Fév 2020
I made some changes in your code
X = 10;
Y = 10;
theta1 = zeros(X,Y);
for n =1:100
theta1 = theta1 + (2/pi)*(((-1)^(n+1)+1)/(n))*sin(n*pi*X1/L).*(sinh(n*pi*Y1/L))./(sinh(n*pi*W/L));
end
surf(X,Y,theta1)
Pay attention to bit-wise operators (i highlighted in red)
  2 commentaires
Jonathan Bird
Jonathan Bird le 21 Fév 2020
Thanks for your help, unfortunately I get the following error message.
Error using surf (line 71)
Data dimensions must agree.
Error in HEAT_TRANSFER_CW (line 40)
surf(X,Y,theta1)
darova
darova le 21 Fév 2020
Try
X = 10;
Y = 10;
[X1,Y1] = meshgrid(1:X,1:Y);
theta1 = zeros(X,Y);
for n =1:100
theta1 = theta1 + (2/pi)*(((-1)^(n+1)+1)/(n))*sin(n*pi*X1/L).*(sinh(n*pi*Y1/L))./(sinh(n*pi*W/L));
end
surf(X,Y,theta1)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Physics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by