Solving a PDE using Method Of Lines
54 次查看(过去 30 天)
显示 更早的评论
Hi everyone
I am trying to solve a PDE through method of lines, using ODE15s.
I get the error message
Not enough input arguments.
Error in TracerFlow (line 3)
dCdt=zeros(Nz,1);
The code script are pasted.
Thanks
% RunTracerFlow
close all
clear all
clc
% Data
tspan = linspace(0,60,61);
L =1;
Nz = 100;
CA0init =0.1;
dz = L./Nz;
Da = 2e-1;
U = 2e-1;
k = 1;
IC = zeros(1,Nz);
% Solver
[t c] = ode15s(@TracerFlow,tspan,IC,[],Nz,CA0init,dz,Da,U,k)
% Recalculation
C(:,1) = CA0init+1./900.*(60.*t-t.^2);
C(:,N+1) = 1./3.*(4.*C(:,Nz) -C(:,Nz-1)); %dCdt = 0
% Plotting
xaxis = linspace(0,L,Nz+1);
yaxis = tspan;
images(xaxis,yaxis,C)
xlabel('axial position')
ylabel('timespan')
colormap jet
colorbar
function dCdt = TracerFlow(t,C,Nz,CA0init,dz,Da,U,k)
% Pre-allocations
dCdt=zeros(Nz,1);
% Define boundary conditions
C(1) = CA0init+1./900.*(60.*t-t.^2);
C(Nz+1) = 1./3.*(4.*C(Nz) -C(Nz-1)); %dCdt = 0
for i = 2:Nz
dCdz(i)= 1./(2.*dz).*(C(i+1)-C(i-1)); %centred
d2Cdz2(i) = 1./(dz.^2).*(C(i+1)-2.*C(i)+C(i-1));
dCdt(i)=Da.*d2Cdz2(i)-U.*dCdz(i)-k.*C(i).^2;
end
end
1 个评论
Alan Stevens
2020-11-3
Hmm. I got a different error message from your code! I corrected it as shown below.
采纳的回答
Alan Stevens
2020-11-3
The crucial lines requiring changes are
[t c] = ode15s(@TracerFlow,tspan,IC,[],Nz,CA0init,dz,Da,U,k)
% Recalculation
C(:,1) = CA0init+1./900.*(60.*t-t.^2);
C(:,N+1) = 1./3.*(4.*C(:,Nz) -C(:,Nz-1)); %dCdt = 0
They should be
[t, C] = ode15s(@TracerFlow,tspan,IC,[],Nz,CA0init,dz,Da,U,k);
% Recalculation
C(:,1) = CA0init+1./900.*(60.*t-t.^2);
C(:,Nz+1) = 1./3.*(4.*C(:,Nz) -C(:,Nz-1)); %dCdt = 0
Also, I replaced images by surf.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Conditions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!