Calling external function in ode45

조회 수: 6 (최근 30일)
Ilias Minas
Ilias Minas 2020년 2월 28일
댓글: Ilias Minas 2020년 2월 28일
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