How do I plot this temperature field ?
10 views (last 30 days)
Show older comments
Siddhant
on 19 Oct 2024
Edited: Divyajyoti Nayak
on 20 Oct 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.
0 Comments
Accepted Answer
Divyajyoti Nayak
on 19 Oct 2024
Edited: Divyajyoti Nayak
on 19 Oct 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!
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!