Coupled ODE using ODE15s with multiple outputs

I am looking to solve 2 sets of coupled ODEs (one with dCp1 and the other with dQp1). When I try to use OD15s using,t,Cp1,Qp1] = ode15s(@solver4,[0,15],horzcat(zeros([1,100]))), I get an error message "[Cp1,Qp1] = ode15s(@solver4,[0,15],zeros(1,100))".
Is there a way for ODE15s to solve these 2 sets of coupled ODEs?
function [dCp1 dQp1] = solver4(t,Cp1,Qp1)
n=100;
D=0.008;
u=1;
dCp1=zeros(n,1);
V=1/n;
Qp1(1)=1;
dQp1=zeros(n,1);
kads=1;
kdes=1;
if t<0.1
Cp1(1)=1;
else
Cp1(1)=0;
end
for i=2:n-1
dCp1(i)=D*((Cp1(i-1)-2*Cp1(i)+Cp1(i+1))/(V^2))+u*((Cp1(i-1)-Cp1(i))/V)-(Qp1(i)-Qp1(i-1))/V;
dQp1(i)=kads*Cp1(i)-kdes*Qp1(i);
end
dCp1(n)=(Cp1(n-1)-Cp1(n))/V;
dQp1(n)=kads*Cp1(n)-kdes*Qp1(n);
end

 Respuesta aceptada

Torsten
Torsten el 26 de Jul. de 2022
Editada: Torsten el 26 de Jul. de 2022
When communicating with ODE15S, the solution must be treated as one vector of size 200, not as two vectors of size 100.
E.g.
function [dCQ] = solver4(t,CQp)
n = 100;
Cp1 = CQp(1:n);
Qp1 = CQp(n+1:2*n);
dCp1 = zeros(n,1);
dQp1 = zeros(n,1);
...
dCQ = [dCp1;dQp1];
end

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by