Help With Creating Phase Plane Portraits
4 views (last 30 days)
Show older comments
% I have a function definition:
function [t,y]=second_order(a0,a1,tspan,y0)
dydt=@(t,y)[y(2);-a0*y(1)-a1*y(2)];
[t,y]=ode45(dydt,tspan,y0);
plot(t,y(:,1))
xlabel('t'),ylabel('y(t)')
title('Numerical Integration')
end
% And I plotted variations. An example would be:
clc
clear
close
a0 = 10;
a1 = 1;
tspan = [0 20];
y0 = [2;0];
[t,y] = second_order(a0,a1,tspan,y0);
legend('a0 = 10, a1 = 1')
% I would change a0 and a1 and plot the results. However, now I am trying to create phase plane portraits. I was given the following to work with:
cla; % clears the current axis (plot) - a weird thing with this phase plane plotter
PhasePlane(@(t,x)second_order(t,x,a0,a1),t,x0) % plots the phase plane
axis square; hold off; % makes sure the axis are square (not stretched)
% I am very new to matlab and have little to no idea how to create phase plane portraits to begin with. I was also given PhasePlane.m to keep in the same directory, along with ode45. How would I create a phase plane portriat using the above information and codes?
% Here is the original question:
Phase plane portraits are a useful visualization tool for evaluating the behavior of second order ODEs, or equivalently two dimensional linear systems, x˙(t) = Ax(t), (6) where A is a 2 × 2 matrix. As the video you watched described, a phase plane portrait creates a vector field by visually plotting arrows that represent the vector-value of the derivative x˙ corresponding to different locations x. The solutions of the system are formed by tracing a curve through the “flow” of these arrows. The original starting point of the curve is the initial condition of the system. I have borrowed some code to make a phase plane plotter for you. Make sure the file PhasePlane.m is downloaded from eLearning and located in the same directory as your other files. I’ve made it so this is called with the same format as ode45:
1 PhasePlane(@(t,x)second_order(t,x,a0,a1),t,x0)
Uncomment the last lines of the stub code to plot the phase plane( seen above). For each of your plots from Section 4, generate a corresponding phase plane portrait with the same parameters and initial conditions. To generate nice plots, you may consider using the subplot command which works like this:
1 figure()
2 subplot(2,1,1) % creates a grid of plots with 2 rows and 1 column
3 % the last argument selects the first location as active
4 plot(t,y);
5 subplot(2,1,2) % selects the second location as active
6 PhasePlane(@(t,x)second_order(t,x,a0,a1),t,x0)
Select three of your plots and discuss in detail how the solution plots of y(t) and the phase plane portraits exhibit the same features/behavior
0 Comments
Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!