Variable inside an ode

조회 수: 17 (최근 30일)
Nora Rafael
Nora Rafael 2019년 11월 13일
댓글: Star Strider 2019년 11월 13일
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
Adam
Adam 2019년 11월 13일
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 2019년 11월 13일
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);

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

채택된 답변

Star Strider
Star Strider 2019년 11월 13일
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
Nora Rafael
Nora Rafael 2019년 11월 13일
Super!
Star Strider
Star Strider 2019년 11월 13일
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by