65.5k views
5 votes
Write a function M-file that implements (8) in the interval 0 ≤ t ≤ 55. Note that the initial condition must now be in the form [yo, v0, w0] and the matrix Y, output of ode45, has now three columns (from which y, v and w must be extracted). On the same figure, plot the three time series and, on a separate window, plot the phase plot using figure (2); plot3 (y,v,w); hold on; view ([-40,60]) xlabel('y'); ylabel('vay); zlabel('way''); Do not forget to modify the function defining the ODE. The output is shown in Figure 9. The limits in the vertical axis of the plot on the left were delib- erately set to the same ones as in Figure 8 for comparison purposes, using the MATLAB command ylim ([-2.1,2.1]). You can play around with the 3D phase plot, rotating it by clicking on the circular arrow button in the figure toolbar, but submit the plot with the view value view ([-40, 60]) (that is, azimuth = -40°, elevation = 60°).

User Rini
by
8.0k points

2 Answers

6 votes

Final answer:

To implement the given equation and plot the time series and phase plot, you can use the ode45 solver in MATLAB. Extract y, v, and w from the output matrix and plot them using the plot and plot3 functions respectively.

Step-by-step explanation:

To write a function M-file that implements the given equation in the interval 0 ≤ t ≤ 55, you can use the ode45 solver in MATLAB. The initial condition should be in the form [yo, v0, w0] and the output matrix Y from ode45 will have three columns representing y, v, and w. You can extract y, v, and w from Y and plot them on the same figure using the plot function. For the phase plot, you can use the plot3 function with the appropriate parameters and view value set to [-40, 60].

User Andrewjj
by
8.4k points
4 votes

Below is an example of a MATLAB script that implements a differential equation using ode45 and then plots the resulting time series and a 3D phase plot is shown below

% Define the function for the ODE

function dydt = myODE(t, Y)

% Parameters

alpha = 0.1;

beta = 0.1;

gamma = 0.1;

% Extract variables from the input vector Y

y = Y(1);

v = Y(2);

w = Y(3);

% Define the system of ODEs

dydt = [

v;

-alpha * v - beta * sin(y) - gamma * w;

beta * v * cos(y) - gamma * w

];

end

% Set the initial conditions

yo = 0;

v0 = 1;

w0 = 0;

% Combine initial conditions into a vector

initialConditions = [yo, v0, w0];

% Define the time span

tspan = [0, 55];

% Solve the ODE using ode45

[t, Y] = ode45(atmyODE, tspan, initialConditions);

% Extract variables from the solution

y = Y(:, 1);

v = Y(:, 2);

w = Y(:, 3);

% Plot time series

figure(1);

subplot(1, 2, 1);

plot(t, y, 'r', t, v, 'g', t, w, 'b');

xlabel('Time');

ylabel('y, v, w');

legend('y', 'v', 'w');

title('Time Series');

% Set the same vertical axis limits for comparison

ylim([-2.1, 2.1]);

% Plot 3D phase plot

subplot(1, 2, 2);

figure(2);

plot3(y, v, w);

hold on;

view([-40, 60]);

xlabel('y');

ylabel('v');

zlabel('w');

title('3D Phase Plot');

% Set the same vertical axis limits for comparison

ylim([-2.1, 2.1]);

% Rotate the 3D plot as needed and then submit with the specified view value

So, to use the code above, one need to Copy the code into a MATLAB script file and then save with a .m extension and then run it in MATLAB.

Note that this script is one that defines the ODE function, solves it using ode45, and plots both the time series and the 3D phase plot on separate figures

Note that in the code, the short form for "at" was written in full because it is showing inappropriate word

User SOA Nerd
by
7.7k points