Calling external function in ode45

2 次查看(过去 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

回答(1 个)

Jeremy
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.
  1 个评论
Ilias Minas
Ilias Minas 2020-2-28
Thanks for your reply.
I save it as ffy.m
I think the problem is with the integral because if i use for example
FractionY=y(5) it works.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by