Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

URGENT CODING NEEDS TO BE DONE WITH IN 5 -6 HOURS, ASAP. PLEASE DO IT ASAP. Writ

ID: 2996422 • Letter: U

Question

URGENT CODING NEEDS TO BE DONE WITH IN 5 -6 HOURS, ASAP. PLEASE DO IT ASAP.

Write a computer program or script to integrate a set of equations of motion of the form = f(t, x, u) For example, a basic approach to this problem is to break up time into discrete units of size dt. If the state xi at time ti is explicitly known, and the applied control ui, is known, then the new state xi+1 at time ti+1 = ti + dt can be approximated by: xi+1 =xi + f(ti, xi, ui)dt This method of numerical integration is known as the Euler method. Due to the properties of this approach, it is only reasonably accurate for very well-behaved systems and sufficiently small time steps dt. You can use any method you know, or can look up, as long as it is time explicit. The Runge-Kutta methods are good examples. Another simple method, for sufficiently small choice of dt is: xi+1/2 =xi +f(ti, xi, ui)dt xi+1 = 1/2 [xi+xi+1/2+ f(ti+1 ,xi+1/2, ui)dt] This predictor-corrector works fairly well for time-independent systems. All of these methods can be extended to multivariable systems by calculating each derivative independently using the information at the current time step, then updating the values and working on the next time step.

Explanation / Answer

function y = integrate(T,X,U)

% Program for integration
% x_dot function of t,x,u

x(1)=X;
h=0.1;
t=1:h:T;

%Evaluate using Euler method
for i=1:T
x(i+1)=x(i)+feval(U,t(i))*h;
end
  
y=x;
end

%_________________________

MATLAB COMMAND

>> y=integrate(100,1,@sin);

Where 100 is number of samples (time)

1 is initial value

sin is function to integrate