Filter löschen
Filter löschen

Integrate inside ode45, every value of a a vector

3 Ansichten (letzte 30 Tage)
Ilias Minas
Ilias Minas am 1 Mär. 2020
Kommentiert: darova am 1 Mär. 2020
Hi everyone,
I have the following part inside a script
if t<=1.5
x=(0:2.51326406981556e-05:2*pi)'; %limits for integration
.
.
.
for i=1:1:250001
Y=(((r.*cos(x)-y(5))-r.*cos(x)+y(6))./((((((r.*cos(x)-y(5))-r.*cos(x)+y(6))).^2+((r.*sin(x)-y(5))+r.*sin(x)).^2).^0.5))); % r is difined in the beginning of the script
Integral(i)=trapz(x,Y);
end
.
.
.
y(5)=y(6);
dy(6)=(-kr*(y(5)+L*y(11))+b*(-kr*(y(6)+L*y(12)))-0.36*Fload*Integral(i))/mcd; % Fload is defined in the beginning.
I want after every time step, which is 1e-5, to use the values of y(5) and y(6) in order to calculate the Integral(i) and use this value for the next calculation of y(5) and y(6).
Practically, i want to integrate every value of Y, which is a function of y(5), y(6), inside [0,2pi], and y(5) and y(6) to be calculated based on this integral.
Is this the correct way for doing this?
Thank you very much.

Akzeptierte Antwort

darova
darova am 1 Mär. 2020
no need of for loop
if t<=1.5
x=(0:2.51326406981556e-05:2*pi)'; %limits for integration
Y=(((r.*cos(x)-y(5))-r.*cos(x)+y(6))./((((((r.*cos(x)-y(5))-r.*cos(x)+y(6))).^2+((r.*sin(x)-y(5))+r.*sin(x)).^2).^0.5))); % r is difined in the beginning of the script
% C1 = r*cos(x) - y(5) + y(6) - r*cos(x);
% C2 = 2*r.*sin(x)-y(5);
% Y=C1./sqrt(C1.^2+C2.^2); % r is difined in the beginning of the script
IntegralY=trapz(x,Y);
end
Show the equations you use
  10 Kommentare
Ilias Minas
Ilias Minas am 1 Mär. 2020
Thats what i am taking...strange
darova
darova am 1 Mär. 2020
Here is what i have for tend=1.5e-02
dashed line: using trapz
solid line: integral=1

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by