Variable inside an ode

13 visualizzazioni (ultimi 30 giorni)
Nora Rafael
Nora Rafael il 13 Nov 2019
Commentato: Star Strider il 13 Nov 2019
I am trying to solve this differential equation: dCb/dt = ((A*D)/(DV*h))*(Cs-Cb). I specify in Matlab the function:
f = @(t,Cb) ((A*D)/(h*DV))*(Cs-Cb)
I use ode45 to solve it:
[t,Cb] = ode45(f, tspan, Cb0);
Full code is below.
However, A is a variable and varies with time itself. It is actually A(t) =0.00155+(0.06043-0.0015)/(1+(t/4481.23119).^0.85949)
How do I add this A function to the below code?
Thanks
tspan = [0 9e4];
dv50=189/1000000000; %m,
dv90=795/1000000000;
r0=dv90/2; %m dv90
rho=1370; %kg/m3
W=18/1000000 %kg
N= W/((4/3)*pi*r0^3*rho);
A=(4*pi*r0^2*N); %m2
MW=402.88
D= 9.9e-9*MW^-0.453 %m2/s % from D(m2/s)=9.9e-9*MW^-0.453
h= r0 %m -
Cs= 0.032 %kg/m3
DV=0.0009 % m3, volume
Cb0=0;
f = @(t,Cb) A*D/(h*DV)*(Cs-Cb)
[t,Cb] = ode45(f, tspan, Cb0);
plot(t,Cb);
title('Bulk Concentration vs Time');
xlabel('Time (s)');
ylabel('Cb (kg/m3)');
legend('Nernst Brunner','Cb_exp');
  2 Commenti
Adam
Adam il 13 Nov 2019
Can you not just replace A in the definition of f, with its above representation in terms of t which is already an input to f?
Nora Rafael
Nora Rafael il 13 Nov 2019
This seemed to work with no errors. But I am concerned as when I plot just this A function alone I get a strange curve.
This is the equation:
equation.JPG
and I implement it this way
SA=0.00155+(0.06043-0.0015)/(1+(t/4481.23119).^0.85949)
This is the curve that I get
Capture.JPG
This is a strange curve as this function should output an exponential decline.
I tested this function separately
function SA_=SurfaceArea(t)
SA_=0.00155+(0.06043-0.0015)/(1+(t/4481.23119).^0.85949);
end
>> t=1:9e4;
>> SA_=SurfaceArea(t)
and I get this error message:
Error using /
Matrix dimensions must agree.
Error in SurfaceArea (line 2)
SA_=0.00155+(0.06043-0.0015)/(1+(t/4481.23119).^0.85949);

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 13 Nov 2019
Try this:
SA = @(t) 0.00155+(0.06043-0.0015)./(1+(t/4481.23119).^0.85949);
f = @(t,Cb) SA(t)*D/(h*DV)*(Cs-Cb)
The rest of your code is unchanged.
  4 Commenti
Nora Rafael
Nora Rafael il 13 Nov 2019
Super!
Star Strider
Star Strider il 13 Nov 2019
Thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by