Euler integration for an ode

3 views (last 30 days)
Matthew Tortorella
Matthew Tortorella on 5 Oct 2021
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

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!