Hello everyone,
I have been looking at ode45 option examples and I can't get my head aroung this one, that seems to appear quite often.
Soory if it's a trivial question by the way; here is the code in question:
[sectioncon,Y]=ode45(@EOM,ppartie,param1,[],[6 5 4 3 2 1]);
What is the use of the empty parenthesis ? and the array of numbers after that ?

6 comentarios

Star Strider
Star Strider el 29 de Abr. de 2020
I do not recognise that ode45 calling syntax. What MATLAB version/release are you using?
The empty square brackets [], denoting the empty array, tell the function (regardless of what the function is) to use the default value for that parameter. They are passed in place of the parameter in that position. (In MATLAB, the order of function arguments is important,)
Lucas Mangin
Lucas Mangin el 29 de Abr. de 2020
Thanks for your reply about the empty array, I am currently using the R2019b version of Matlab
Star Strider
Star Strider el 29 de Abr. de 2020
My pleasure.
Do you have any clue as to what MATLAB version was used for that ode45 call? Is tthere any indication in the code itself? As I mentioned, it does not look at all familiar to me.
Lucas Mangin
Lucas Mangin el 29 de Abr. de 2020
I tried finding the original program but to no avail, so I don't have any clues on what is the version employed.
Star Strider
Star Strider el 29 de Abr. de 2020
Editada: Star Strider el 29 de Abr. de 2020
If that code still works, then it might be best just to leave it alone. If it has problems, it’s probably possible to rewrite it into more recent syntax so it will run correctly. For that, it’d be necessary to see some of the code preceeding it.
EDIT — If it runs as written, just leave it alone. It may not be worth the effort to make it compatible with the current syntax, unless it’s going to be used frequently in the future. In that situation, rewriting some of the rest of it for the same reason would also be appropriate.
Lucas Mangin
Lucas Mangin el 29 de Abr. de 2020
Thanks for your insight, I posted a more detailed code as response to Steven Lord's answer, if your interested.

Iniciar sesión para comentar.

 Respuesta aceptada

Steven Lord
Steven Lord el 29 de Abr. de 2020

0 votos

That is an old syntax, one that remains for backwards compatibilty purposes, for passing additional parameters into functions specified in an ode45 call. The empty square brackets indicate that you want ode45 to use the default options and to pass whatever follows it into your ODE function. I'm not certain offhand but I think that syntax was removed from the documentation probably 10-15 years ago when the introduction of anonymous functions and nested functions made those techniques the preferred way to parameterize your functions.

1 comentario

Thanks a lot for the support and for letting me know that, wasn't expecting the syntax to be that much old. I'll probably keep it for the time being on the program, and I'll update it on newer iterations;
Here is the function EOM reffered in the ode45 :
function dX=EOM(A,y,param);
%% gamma%%
gam=1.4;
%% definition of initial conditions vector %%
rho0=param(1);T0=param(2);p0=param(3);v0=param(4);M0=param(5);
%% definition of the function vector %%
rho=y(1);
T=y(2);
p=y(3);
v=y(4);
M=y(5);
vson=sqrt(gam*8*T);
%% definitions of diferential equations%%
drho=-((v*v)/(vson*vson))/((v*v)/(vson*vson)-1)*rho/A;
dT=-(gam-1)*(v*v)/(vson*vson)/((v*v)/(vson*vson)-1)*T/A;
dp=-gam*(v*v)/(vson*vson)/((v*v)/(vson*vson)-1)*p/A;
dv=1/((v*v)/(vson*vson)-1)*v/A;
dM=(2+(gam-1)*M^2)/(M^2-1)*M/A;
dX=[drho;dT;dp;dv;dM];
end
If I am to remove the [ 6 5 4 3 2 1],the program breaks and it displays this message error :
I hope all this helps.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 29 de Abr. de 2020

Editada:

el 29 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by