フィルターのクリア

Euler integration for an ode

4 ビュー (過去 30 日間)
Matthew Tortorella
Matthew Tortorella 2021 年 10 月 5 日
回答済み: Nipun 2024 年 5 月 16 日
I have the following system:
m(dx2/dt2)=-C(dx/dt)-kx+mgsin(phi)+u
du/dt=-au+mu
with tracking error=e=xd-x.
I have assigned 100 random values to xd,x,m,C,k,phi (within -pi and pi). I am trying to use Euler integration to plot e(t) for the 100 random variable assignments and my code is posted below. I am getting a weird output for my plot and I don't know if its a problem with my code or me not using the euler integration formula correctly. I am expecting the plot of r(t) to exponentially decay to zero based on my analysis of the system. Any help on this issue is greatly appreciated.
low=0;
high=5;
m=(high-low).*rand(100,1) + low;
c=(high-low).*rand(100,1) + low;
k=(high-low).*rand(100,1) + low;
a=(high-low).*rand(100,1) + low;
alpha=(high-low).*rand(100,1) + low;
lowphi=-1*pi;
highphi=pi;
phi=(highphi-lowphi).*rand(100,1) + lowphi;
xd=(high-low).*rand(100,1) + low;
x=(high-low).*rand(100,1) + low;
dt=0.1;
Xxd=xd(1):dt:xd(100);
e=zeros(size(Xxd));
e(1)=xd(1)-x(1);
n=numel(e);
for i=1:n-1
e(i+1)=e(i)+dt*(xd(i)-x(i));
plot(e)
xlabel('Time')
ylabel('x1(t)')
hold on
end
hold off

回答 (1 件)

Nipun
Nipun 2024 年 5 月 16 日
Hi Matthew,
I understand that you are trying to simulate a dynamic system using Euler integration and plot the tracking error ( e(t) ) over time for 100 random variable assignments. Your expectation is for the plot of ( e(t) ) to exponentially decay to zero based on your system's analysis. However, the issue you are facing with an unexpected plot output might be due to the incorrect application of Euler's method and the way you are handling the loop and plotting within it.
To correctly implement Euler's method and plot the tracking error for your system, you should first ensure that the dynamics of ( e(t) ) are correctly modeled. Given that you have a dynamic system and an auxiliary equation for ( u ), Euler's method should be applied to both equations with appropriate updates at each time step.
Here is an example code snippet in MATLAB that corrects these issues:
% Define simulation parameters
dt = 0.1; % Time step
T = 10; % Total simulation time
time = 0:dt:T; % Time vector
n = numel(time); % Number of time steps
% Preallocate arrays for efficiency
e = zeros(100, n); % Tracking error for 100 random assignments
% Loop over 100 random assignments
for j = 1:100
% Generate random parameters
low = 0; high = 5;
m = (high-low).*rand + low;
C = (high-low).*rand + low;
k = (high-low).*rand + low;
a = (high-low).*rand + low;
mu = (high-low).*rand + low; % Assuming alpha is mu in your auxiliary equation
lowphi = -pi; highphi = pi;
phi = (highphi-lowphi).*rand + lowphi;
xd = (high-low).*rand + low;
x = (high-low).*rand + low;
u = 0; % Initial condition for u, adjust as necessary
% Initial tracking error
e(j, 1) = xd - x;
% Euler integration
for i = 1:n-1
% System dynamics (simplified example, replace with your actual dynamics)
dx = -C/m*(x-xd) - k/m*(x-xd) + sin(phi) + u/m; % dx/dt
du = -a*u + mu; % du/dt
% Update
Hope this helps.
Regards,
Nipun

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by