clc;Funderin(1) = 1.7153;Funderout(1) = 1;Fsep(1) = 0.9406;MassUnders(1) = 12.0069;tspan1 = linspace(0, 3, 25);tspan2 = linspace(3, 5, 25);Funderin(2) = 1;Funderout(2) = 0.5;Fsep(2) = 0.2;MassUnders(2) = 8;Funderin(3) = 0.5;Funderout(3) = 0.2;Fsep(3) = 0.1;MassUnders(3) = 5;Cu_in(1) = 0.9717 %tracer flow
Cui = 0; %initial concentration
rhs = @(t,Cu,Cu_in) (Funderin(1)* Cu_in(1) - Funderout(1)*Cu(1) - Fsep(1)*Cu(1))/MassUnders(1);rhs = @(t,Cu,Cu_in) (Funderin(2)* Cu(1) - Funderout(2)*Cu(2) - Fsep(2)*Cu(2))/MassUnders(2);rhs = @(t,Cu,Cu_in) (Funderin(3)* Cu(2) - Funderout(3)*Cu(3) - Fsep(3)*Cu(3))/MassUnders(3);[t,Cu]=ode45( @(t,Cu) rhs(t,Cu,Cu_in), tspan1, Cui);Cu_int = [t, Cu];Cu_in = 0;Cui = Cu(end);[t,Cu]=ode45( @(t,Cu) rhs(t,Cu,Cu_in), tspan2, Cui);Cu_int = [Cu_int; t, Cu];plot(Cu_int(:,1),Cu_int(:,2));xlabel('Time'); ylabel('Cu');
The end goal is to get rhs looped for i = 1:K, where K can be upwards 50. But I can't even seem to get Cu to 'save' properly. Any ideas?
Best Answer