How do I plot this temperature field ?
Mostrar comentarios más antiguos
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
Más respuestas (0)
Categorías
Más información sobre Annotations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
