Pr4oblem with an ODE 45 " not enough input arguments"

1 vue (au cours des 30 derniers jours)
Francesco Renzulli
Francesco Renzulli le 7 Jan 2021
I have problem withis system of ode , this is onlya part of the code
N.B I have the latest version of MatLab.
Thanks for your help
Nt=150
m_ox=0.7;
m_ox=m_ox.*ones(1,Nt);
r_dot=0.0006
m_dot_pr=1.7 ;
v_cham=1*10^(3);
m_fuel= 15.*ones(1,Nt);
burn_time=50;
t=linspace(0,burn_time,Nt)
C=((m_dot_fuel+m_ox-m_dot_pr)./(v_cham)) ;
A=((4*r_dot)./Dp_t);
y1_0=zeros(Nt,1);
y1_0=y1_0(:);
t=t(:);
y2_0=rho_ox_0.*ones(1,Nt);
y2_0=y2_0(:);
y_0=[y1_0,y2_0];
[t_sol,y_sol]=ode45(@(t,y1,y2)zero_dmodelcc(C,A,y1,y2,t,v_cham,m_dot_pr,m_ox),t,y_0);
function dy=zero_dmodelcc(C,A,y1,y2,t,v_cham,m_dot_pr,m_ox)
y=[y1;y2];
v_cham=v_cham(:);
m_ox=m_ox(:);
C=C(:);
A=A(:);
dy1 =C-(y1.*A);
dy1=dy1(:);
dy2=((y1.*m_ox)./(v_cham))+y2.*(A-m_dot_pr);
dy2=dy2(:);
dy=[dy1,dy2];
end

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 7 Jan 2021
Your definition of the ODEs is unconventional. I've always used to define coupled ODEs such that the dependent variables are in one array in the input, not as two separate ones. So, according to my understanding you should modify the zero_dmodelcc function like this:
function dy=zero_dmodelcc(C,A,y1y2,t,v_cham,m_dot_pr,m_ox)
y1 = y1y2(1); % or perhaps y1 = y1y2(1:end/2);
y2 = y1y2(2); % and if so y2 = y1y2(end/2+1:end);
v_cham=v_cham(:);
m_ox=m_ox(:);
C=C(:);
A=A(:);
dy1 =C-(y1.*A);
dy1=dy1(:);
dy2=((y1.*m_ox)./(v_cham))+y2.*(A-m_dot_pr);
dy2=dy2(:);
dy=[dy1(:);dy2(:)]; % Should be a column-vector IIRC
end
Further you somehow define the initial conditions to be of the same size as the time-variable. That doesn't make sense. Something is likely off.
  1 commentaire
Francesco Renzulli
Francesco Renzulli le 7 Jan 2021
thank you, I am beginner in MATLAB, and people like you are really helpfull

Connectez-vous pour commenter.

Plus de réponses (1)

Cris LaPierre
Cris LaPierre le 7 Jan 2021
The ode solver expects the first two inputs to your odefun should be t and y (you can use any variable name you want, but this is what they represent). They are not defined in the code. Any additional input parameters come after that. Have a look at this example on the ode45 documentation page.
I agree your setup is unconventional. I would add that you use t incorrectly - both as the tspan input, and the odefun t input. Here's how you can modify the code to fix those issues at least.
ts = ts=linspace(0,burn_time,Nt);
y_0=[0,0];
[t_sol,y_sol]=ode45(@(t,y) zero_dmodelcc(t,y,C,A,v_cham,m_dot_pr,m_ox),ts,y_0);
function dy=zero_dmodelcc(t,y,C,A,v_cham,m_dot_pr,m_ox)
y1 = y(1);
y2 = y(2);

Community Treasure Hunt

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

Start Hunting!

Translated by