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

Q2. Write a for loop in MATLAB that is able to approximate the angular position

ID: 3838111 • Letter: Q

Question

Q2. Write a for loop in MATLAB that is able to approximate the angular position using the trapezoid rule

Angular position is the integral of angular velocity with respect to time. This can be approximated with the trapezoid rule, which states that:

We have been given a csv file with 2 columns and 1000 rows of data, column 1 is time from 1-10 sec and column 2 is angular acceleration. This was then imported into MATLAB using csvread. So the code will need to work with this data.

Note*** In-built functions can be used to check your answers, but should not be used in the solution algorithm.

w(t) w (ti At x At

Explanation / Answer

Q = trapz(Y) returns the approximate integral of Y via the trapezoidal method with unit spacing. The size of Y determines the dimension to integrate along:

If Y is a vector, then trapz(Y) is the approximate integral of Y.

If Y is a matrix, then trapz(Y) integrates over each column and returns a row vector of integration values.

If Y is a multidimensional array, then trapz(Y) integrates over the first dimension whose size does not equal 1. The size of this dimension becomes 1, and the sizes of other dimensions remain unchanged.

Q = trapz(X,Y) integrates Y with spacing increment X. By default, trapz operates on the first dimension of Y whose size does not equal 1. length(X) must be equal to the size of this dimension . If X is a scalar, then trapz(X,Y) is equivalent to X*trapz(Y).

Q = trapz(___,dim) integrates along the dimension dim using any of the previous syntaxes. You must specify Y, and optionally can specify X. The length of X, if specified, must be the same as size(Y,dim). For example, if Y is a matrix, then trapz(X,Y,2) integrates each row of Y.

Trapezoidal Method

trapz performs numerical integration via the trapezoidal method. This method approximates the integration over an interval by breaking the area down into trapezoids with more easily computable areas.

For an integration with N+1 evenly spaced points,

Use trapz and cumtrapz to perform numerical integrations on discrete data sets. Use integral, integral2, or integral3 instead if a functional expression for the data is available.

trapz reduces the size of the dimension it operates on to 1, and returns only the final integration value. cumtrapz also returns the intermediate integration values, preserving the size of the dimension it operates on.