Conclude Variables for an Input Argument
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Dyuman Joshi
2023-5-26
Are the variables other than x constant? If so, then you can define them inside the ODE function.
回答(1 个)
Abhijeet
2023-5-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!