Conclude Variables for an Input Argument
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hey guys,
So i got following function:
function dxdt = odefcn(x, m, Fvy, Fhy, Fvx, Fhx, Fwx,Fwy, Mav, Mah, Mbv, Mbh, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t)
Is there a way to apply a callname to the odefcn for easier handling and more clearness.
When I use it as an Input argument in
[t,x] = ode45(@(t,x) odefcn(x, m, Fvy, Fhy, Fvx, Fhx, Fwx,Fwy, Mav, Mah, Mbv, Mbh, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t),tspan,x);
I don't want to write down every variable again. Maybe theres even a way to define a line range, in which every variable should be used?
Thanks in advance!
2 Commenti
Dyuman Joshi
il 26 Mag 2023
Are the variables other than x constant? If so, then you can define them inside the ODE function.
Risposte (1)
Abhijeet
il 30 Mag 2023
Hi,
Unfortunately there is no way to define a line range for the variables to be used. Every necessary variable should be explicitly included in the function definition.
However, you can create structures for similar params that are needed and then use the same in your function call, and within the function you can reference the variables that you need.
%Define the funtion with fewer arguments by grouping
function dxdt = odefcn(x, m, F, M, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t)
% Call the function with the modified arguments
[t,x] = ode45(@(t,x) odefcn(x, m, F, M, r,iz,delta,lv,lh,Jv,Jh,cs,ca,cy,cx,vFvxstat,vFvystat,t),tspan,x)
For example,
You can group the F & M params together and reference their variables inside the function.
% You can reference the variables in the structure inside your function
% like this
Fvy = F.vy;
Fhy = F.hy;
Fvx = F.vx;
Fhx = F.hx;
Fwx = F.wx;
Fwy = F.wy;
Mav = M.av;
Mah = M.ah;
Mbv = M.bv;
Mbh = M.bh;
This can help you enhance the readability and make the code more structured.
Thanks
0 Commenti
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!