Numerical Solution/Simulation Euler Method, Applied to a Single 1st Order ODE q1(t)=x(t), m=0 kg, c=1Ns/m, k=5 N/m
A particular simulation with x(0)=q1(0)=0, and F(t)=u(t)=0, t<0, F(t)=u(t)=1 N, t>0
Euler Method, Applied to a Set of 1st Order ODE’s
q1(t)=x(t), q2(t)= x(t), m=1 kg, c=0.5Ns/m, k=1 N/m q1(0)=0, q2(0)=0
q1(0)=0 m, q2(0)= 0 m/s, F(t)=u(t)=0, t<0, F(t)=u(t)=1 N, t>0
Code Modules Required to Use ODE45 in Matlab
q1(t)=x(t), q2(t)= x(t), m=1 kg, c=0.5Ns/m, k=1 N/m q1(0)=0, q2(0)=0
N=5000; tend=100; t=linspace(0,tend,N); % Set up initial conditions for nonlinear model ics=[ 15 15 15 -15 -15 -15 ; ... -10 -8 -6 6 8 10 ]; % ics1=[ 10 5 -5 -10 ; ... % -10 -10 10 10 ]; %ics=[ics ics1]; for i1=1:6 xo=ics(:,i1) % Simulate Nonlinear Model [t,x]=ode45('InvPendNonlin',t,xo); % Plot simulation of nonlinear model subplot(2,1,1); plot(t,x(:,1),t,x(:,2)); %axis([0 tend -360 360 ]); xlabel('time (sec)'); ylabel('x1 (rad), x2 (rad/sec)'); title(['x1(0)=',num2str(xo(1)),'x2(0)=',num2str(xo(2))]); grid on; %hold on subplot(2,1,2); plot(x(:,1),x(:,2)); %axis([0 2000 0 50]); xlabel('x1 (rad)'); ylabel('x2(rad/sec)'); hold on; pause; end