I need to solve the series for two different cases D1 and D2 specified
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The original question:
(C(x,t) -C0 )/(Cb- C0) = 1- 4/pi ∑ (-1)^n /(2*n +1) exp [ -(2*n+1)^2 *(pi)^2 *D*t/4*l^2] * cos((2*n+1)*pi*x)/2*l) . Plot C/Cb on the same plot for the two cases ; D1= 6.0*10^-7 , D2= 3.0*10^-6, C0=2, Cb=0 , l=3 mm . Also label the curve and use minute for time. Solve this problem in matlab .
Matlab code
% Given parameters
D1 = 6.0e-7; % Diffusion coefficient for Case 1
D2 = 3.0e-6; % Diffusion coefficient for Case 2
C0 = 2; % Initial concentration
Cb = 0; % Boundary concentration
l = 0.003; % Length scale (in meters)
% Define x and t (adjust as needed)
x = linspace(0, l, 100); % Spatial domain (from 0 to l)
t_minutes = linspace(0, 60, 100); % Time domain (in minutes)
% Initialize matrices to store results
R1 = zeros(length(x), length(t_minutes));
R2 = zeros(length(x), length(t_minutes));
% Calculate R(x,t) for both cases
for i = 1:length(x)
for j = 1:length(t_minutes)
R1(i, j) = (C(x(i), t_minutes(j), D1, C0, Cb, l) - C0) / (Cb - C0);
R2(i, j) = (C(x(i), t_minutes(j), D2, C0, Cb, l) - C0) / (Cb - C0);
end
end
% Plot R(x,t) for both cases
figure;
surf(t_minutes, x, R1, 'DisplayName', 'Case 1');
hold on;
surf(t_minutes, x, R2, 'DisplayName', 'Case 2');
xlabel('Time (minutes)');
ylabel('Position (meters)');
zlabel('C(x,t) / C_b');
title('Concentration Ratio: C(x,t) / C_b');
legend;
grid on;
% Concentration function (you can adjust this based on your specific problem)
function C_val = C(x, t, D, C0, Cb, l)
C_val = 1 - (4/pi) * sum((-1).^((0:1000)) ./ (2*(0:1000) + 1) ...
.* exp(-(2*(0:1000) + 1).^2 * pi^2 * D * t / (4*l^2)) ...
.* cos((2*(0:1000) + 1) * pi * x / (2*l)));
end
The code yields weird results. Need some help correcting the code . Thanks
1 Kommentar
Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!