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

Answer using Matlab: Consider the nonlinear two-dimensional system y(t) = (x + y

ID: 2264762 • Letter: A

Question

Answer using Matlab:
Consider the nonlinear two-dimensional system y(t) = (x + y)(y + 3) 1. Use solve" to find all of the equilibrium solutions to this problem (that is, all points (,y) for which r'(t) y(t)-0). 2 Use ode45 to plot representative solutions for this problem in the phase plane, i.e., plot y(t) vs r(t). First, create a new plot with a viewing window that includes all of the above equilibrium points, plus one unit in the r and y directions. You can calculate the r and y ranges either by hand, or by applying "min" and "max" to the output of Task 1 to find the range of z and y equilibrium values, adding a one to the upperend, and subtracting one from the lower end. You'll also need to use "double" to translate the output of your symbolic computation from Task 1 to floats if using the second option. Use "axis" to set the range of your plot (You'll either need to repeat the "axis" command after each time you plot a new solution, or once at the end, as Matlab will rescale the window to fit the plot range each time you plot a new solution.) Select a representative set of initial values either by hand or by creating a grid using nested for-next loops. Solve forward and backward in time from each initial condition that you choose. You can solve backward in time by making the second argument in the time interval argument to ode45 less than the first, e.g., enter [0, -21 instead of [0, 2]. Plot each solution on the phase plane. Note that you do NOT need to construct a legend for this exercise.

Explanation / Answer

Here is function named drawPhase that solves the question. Please note that you need to copy the code and save in a file named drawPhase.m. Then you can run the file either in command window or directly using run button. If you have doubts comment on the solution. I have tried my best to explain the code by comments in the code.

-----------------------------------------------------------------------------------------------------------------

function eqp = drawPhase()
clc
  
%% Part 1 of the question
%define symbolic x and y
x = sym('x');
y = sym('y');
  
%solve for equalibrium points
pe = solve((x-y)*(x-5)==0, (x+y)*(y+3)==0);
  
% x-values of equalibrium points
xe = double(pe.x);
  
% y-values of equalibrium points
ye = double(pe.y);
  
% output equalibrium points
eqp = [xe, ye];
  
%% Part 2 of the question
  
% calculate x limits for plot window
xl = [min(xe)-1, max(xe)+1];
  
% calculate x limits for plot window
yl = [min(ye)-1, max(ye)+1];
  
% define maximum |t|
tmax = 2;
  
% plot eqalibrium points
scatter(xe, ye, 'r*')
  
%hold on the graph so that subsequent plot are on the same plot
hold on
  
% create initial point (values) to solve
for x0 = xl(1):xl(2)
for y0 = yl(1):yl(2)
  
% solve forward
[~, X] = ode45(@f, [0, tmax], [x0 y0]);
  
% get x and y component from solution
x = X(:,1);
y = X(:,2);
  
% plot solution
plot(x,y,'--')
  
% solve backward
[~, X] = ode45(@f, [0, -tmax], [x0 y0]);
  
% get x and y component from solution
x = X(:,1);
y = X(:,2);
  
% plot solution
plot(x,y,'--')
end
end
  
%set x and y limits
xlim(xl);
ylim(yl);
end

% derivative calculator function
function dxdy = f(~,xy)
%get x and y from argument to f(t,(x,y))
x = xy(1);
y = xy(2);
  
%calculate [dx/dt; dy/dt] as a column
dxdy = [(x-y)*(x-5); (x+y)*(y+3)];
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote