Conclude Variables for an Input Argument
3 views (last 30 days)
Show older comments
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 Comments
Dyuman Joshi
on 26 May 2023
Are the variables other than x constant? If so, then you can define them inside the ODE function.
Answers (1)
Abhijeet
on 30 May 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 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!