ode45 solve and taking current state as input

Hi
Can anyone help me how to fix this problem?
my questions are blow:
this is my function to be solved:
function dx = CSmacro_derive(x,fluid_params,dQ,dV,h_in,dm_in,dm_out)
dx=zeros(3,1);
v=x(1)/x(2);
h=fluid_params.h;
P=fluid_params.P;
dx(1)=dV;
dx(2)=dm_in-dm_out;
dx(3)=(1/(x(2)*fluid_params.dudT))*...
(dQ+((h_in-h)*dm_in)+(P+fluid_params.dudv)*(v*dx(2)-dx(1)));
end
This my main script:
t=linspace(0,10,10);
dV =0.1*sin(t);
dm_in=0.5;
dm_out=0;
% Initial condition
V=0.3326;
m=1;
T=15 + Kel;
x0=[V;m;T];
% Upstream refrigerant
v_in = 0.3326;
T_in = 15 + Kel;
fluid_in = refprop(v_in,T_in,r410a);
h_in=fluid_in.h;
[~,~,dQ] = convecCool(theta_a,x(3),convec_params);
fluid_params = CSmacro_props(x,r410a);
%this is my question.
%how can I take the current x value as my input to these two functions.
for i=length(t)
dx = @(t,x) CSmacro_derive(x,fluid_params,dQ,dV(i),h_in,dm_in,dm_out);
opts=odeset('RelTol',1e-6);
[t,x] = ode45(dx,t,x0,opts);
end
Thanks!

6 comentarios

Torsten
Torsten el 24 de Abr. de 2019
By calling "convecCool" and "CSmacro_props" from "CSmacro_derive"
WANYI ZHANG
WANYI ZHANG el 24 de Abr. de 2019
Can you write a little bit detailed codes?
Thanks a lot
Torsten
Torsten el 24 de Abr. de 2019
Editada: Torsten el 24 de Abr. de 2019
Put the lines marked in bold after the line
function dx = CSmacro_derive(x,fluid_params,dQ,dV,h_in,dm_in,dm_out)
and remove fluid_params,dQ from the list of passed parameters (because they are recalculated now in "CSmacro_derive" for the actual x-vector):
function dx = CSmacro_derive(x,dV,h_in,dm_in,dm_out)
WANYI ZHANG
WANYI ZHANG el 24 de Abr. de 2019
I fixed it.
but my dV is not passing properly.
Do you know why?
Torsten
Torsten el 24 de Abr. de 2019
You changed
dx = @(t,x) CSmacro_derive(x,fluid_params,dQ,dV(i),h_in,dm_in,dm_out);
to
dx = @(t,x) CSmacro_derive(x,dV(i),h_in,dm_in,dm_out);
?
Jan
Jan el 24 de Abr. de 2019
I've formatted the code as code to improve the readability. Please do this by your own in future posts. Thank you.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 24 de Abr. de 2019

Comentada:

Jan
el 24 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by