필터 지우기
필터 지우기

I need to solve the series for two different cases D1 and D2 specified

조회 수: 2 (최근 30일)
Bijaya
Bijaya 2024년 3월 7일
편집: Torsten 2024년 3월 7일
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
Torsten
Torsten 2024년 3월 7일
편집: Torsten 2024년 3월 7일
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 .
You cannot plot C/Cb since Cb = 0. Or did you copy your assignment incorrectly ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by