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

Please use simulink and matlab to solve. Be sure to label and title all plots 1)

ID: 665216 • Letter: P

Question

Please use simulink and matlab to solve.

Be sure to label and title all plots 1). For the following differential equation: dt dt Develop the simulation using integrators and run that simulation for x being a unit step Plot y as a function of t. Replace the analog integrator with a forward Euler integrator and trapezoidal integrator using a sampling time of 0.05. Run both the Euler and trapezoidal simulations and plot the output y For the trapezoidal integrator, there is an algebraic loop. Eliminate that loop by developing the difference equation for y(n) analytically again for a sampling time of 0.05 Hint for the trapezoidal integrator, the discrete-time transfer function is given by: a. b. c. G(z)=G(s d. Write a MatlabB script to solve the difference equation. Compare results to analog, the forward Euler, the trapezoidal simulation, and the result by solving and eliminating the algebraic loop in part oc e.

Explanation / Answer

function yprime = lv(t, y) % lotka volterra vector field r=2;

%coefficient yprime =[0;0];

%creates a column vector with two elements yprime(1) = r*y(1)*(1 - y(2));

yprime(2) = y(2)*(y(1) - 1);

The following m-le implements Euler’s Method. euler.m
function [ylist, tlist] = euler(y0, t0, m, vf, h, N) % solves dy/dt = f(y,t) in R^m starting from y(t0)=y0, using N steps of size h % the initial condition should be an m-dimensional column vector % vf(y,t) should evaluate the vector field f at the point (y,t) % results are returned in tlist and ylist, the latter in the form of a matrix, each % of whose columns represent the numerical solution at a timestep
tlist = zeros(1, N + 1); ylist = zeros(m, N + 1); tlist(1) = t0; ylist(:, 1) = y0;
for nn = 1:N, tlist(nn + 1) = t0 + nn * h; ylist(:, nn + 1) = ylist(:, nn) + h * feval(vf, tlist(:, nn), ylist(:, nn)); end