Calling external function in ode45
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have the following equation of motion in a system of 6 equations of motion, which are solveed using ode45.
dy(6)=(-kr*(y(5)+L*y(11))+b*(-kr*(y(6)+L*y(12)))-m*Fload*FractionY)/mcd;
All the parameters (kr, L, b, m, Fload and mcd) are defined in the beggining of the code.
The FractionY parameter, though is calculated using the following integral
x=(0:2.513274e-6:2*pi)'; % [rad] for numeric intergration
Y=(((oc)*(r*cos(x)-y(5))-ob*r*cos(x)+y(6))/(((((oc)*(r*cos(x)-y(5))-ob*r*cos(x)+y(6)))^2+(-oc*(r*sin(x)-y(5))+ob*r*sin(x))^2)^0.5))'; %[-] dimensionless function
FractionY =(1/(2*pi))*trapz(x,Y); % [-] Numeric Intergraiton
In which oc, ob are funcions that are defined in the beggining of the script.
I want for every value of y(5), y(6) the FractionY term to be calculated again and after solve the system of equations.
Currenlty i created the following script in order to use FractionY as an external function, without any success.
function FractionY=ffy(y)
global cdspeed fwspeed FrictionFractionY x oc ob Y
oc=((cdspeed*2*pi)/60)';
ob=((fwspeed*2*pi)/60)';
x=(0:2.513274e-6:2*pi)'; % [rad] for numeric intergration
Y=(((oc)*(r*cos(x)-y(5))-ob*r*cos(x)+y(6))/(((((oc)*(r*cos(x)-y(5))-ob*r*cos(x)+y(6)))^2+(-oc*(r*sin(x)-y(5))+ob*r*sin(x))^2)^0.5))';
FrictionFractionY =(1/(2*pi))*trapz(x,Y);
end
And in my main code i define Fraction as :
FractionY=ffy(y)
How can i make it work?
Thank you in advance
0 个评论
回答(1 个)
Jeremy
2020-2-28
function FractionY=ffy(y)
Did you save this function as FractionY.m or as ffy.m? Because as it's written, the function is actually ffy. If the file save name is different than the function name it won't work.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!