Calling external function in ode45

6 Ansichten (letzte 30 Tage)
Ilias Minas
Ilias Minas am 28 Feb. 2020
Kommentiert: Ilias Minas am 28 Feb. 2020
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

Antworten (1)

Jeremy
Jeremy am 28 Feb. 2020
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 Kommentar
Ilias Minas
Ilias Minas am 28 Feb. 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by