Integrate inside ode45, every value of a a vector

4 次查看(过去 30 天)
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.

采纳的回答

darova
darova 2020-3-1
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 个评论
darova
darova 2020-3-1
Here is what i have for tend=1.5e-02
dashed line: using trapz
solid line: integral=1

请先登录,再进行评论。

更多回答(0 个)

类别

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