How do I plot this temperature field ?

8 visualizaciones (últimos 30 días)
Siddhant
Siddhant el 19 de Oct. de 2024
Editada: Divyajyoti Nayak el 20 de Oct. de 2024
I have a temperature field with boundary conditions T(x=0,y)= To for jL<y<(j+0.5)L and 0 for for (j + 0.5)L < y < (j + 1)L, and
limx→∞ ∇T(x, y) = 0. where j = 0, ±1, ±2, . . .. I used fourier decomposition method to find the general solution
T(x,y)= To/2 +
. where n= odd integers only. and B=2To/(pi.n).
My code to plot this behavior....
% MATLAB code to plot temperature with y on the y-axis and x on the x-axis
% Define constants
T0 = 1; % Maximum temperature
L = 1000; % Period length
n_max = 10000; % Maximum number of terms in the Fourier series
% Define the ranges for x and y
x = linspace(0, 1000, 50); % x from 0 to 2
y = linspace(0, 5 * L, 500); % y from 0 to 5L
% Initialize the figure
figure;
hold on;
% Loop through values of x
%Marked section starts
for ix = 1:length(x)
T = zeros(size(y)); % Initialize the temperature array for the current x
% Calculate temperature for each y using Fourier series
for n = 1:2:n_max % Only odd n
bn = 2 * T0 / (pi * n); % Fourier coefficient
% Calculate the temperature for the current y and x
T = T + bn * sin(2 * pi * n * y / L) .* exp(-2 * pi * n * x(ix) / L);
end
% Plot the temperature against y for the current x
plot(y, T, 'DisplayName', sprintf('x = %.2f', x(ix)));
end
%Marked section ends
% Customize the plot
xlabel('y (Position along the boundary)');
ylabel('Temperature T(x, y)');
title('Temperature Waves Decaying with Increasing x');
grid on; % Add grid for better visualization
legend show; % Show legend for different x values
hold off;
My problem is according to my question the temperature field should not oscillate to negative value. but my code plots a graph with negative values. and at infinity the temperature is decaying to zero.
The graph should look alike a sqaure wave oscialltion from postive value to zero and as x increases the wave is slowly decaying and at x=infinity the temperature should be constant.

Respuesta aceptada

Divyajyoti Nayak
Divyajyoti Nayak el 19 de Oct. de 2024
Editada: Divyajyoti Nayak el 19 de Oct. de 2024
I see that you're trying to plot the general solution you have found but the equation given and the equation in the code don't match. The equation in the code does not contain the "T0/2" term.Furthermore, from the described desired result, I think the "T0/2" inside the summation is a mistake. I edited the code to get a plot that looks similar to the desired result.
% MATLAB code to plot temperature with y on the y-axis and x on the x-axis
% Define constants
T0 = 1; % Maximum temperature
L = 1000; % Period length
n_max = 10000; % Maximum number of terms in the Fourier series
% Define the ranges for x and y
x = linspace(0, 1000, 50); % x from 0 to 2
y = linspace(0, 5 * L, 500); % y from 0 to 5L
% Initialize the figure
figure;
hold on;
% Loop through values of x
%Marked section starts
for ix = 1:length(x)
T = zeros(size(y)); % Initialize the temperature array for the current x
% Calculate temperature for each y using Fourier series
for n = 1:2:n_max % Only odd n
bn = 2 * T0 / (pi * n); % Fourier coefficient
% Calculate the temperature for the current y and x
T = T + bn * sin(2 * pi * n * y / L) .* exp(-2 * pi * n * x(ix) / L);
end
T = T + T0/2;
% Plot the temperature against y for the current x
plot(y, T, 'DisplayName', sprintf('x = %.2f', x(ix)));
end
%Marked section ends
% Customize the plot
xlabel('y (Position along the boundary)');
ylabel('Temperature T(x, y)');
title('Temperature Waves Decaying with Increasing x');
grid on; % Add grid for better visualization
legend show; % Show legend for different x values
hold off;
Hope this helps!
  2 comentarios
Siddhant
Siddhant el 20 de Oct. de 2024
Thankyou @Divyajyoti Nayak for pointing out the mistake. This is excatly what I wanted to plot.
I really appreciate your effort.
Divyajyoti Nayak
Divyajyoti Nayak el 20 de Oct. de 2024
Editada: Divyajyoti Nayak el 20 de Oct. de 2024
You're welcome @Siddhant!! It would help others if you could mark the answer as accepted.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Annotations 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!

Translated by