Successfully implement harmonic oscillator phase plot

2 views (last 30 days)
I'm trying to implement this first order ODE:
This is the current code I have written:
%set up the requirements
xval = linspace(-5, 5, 20);
vval = linspace(-5, 5, 20);
[x, v] = meshgrid(xval, vval);
dotx = NaN(size(x));
dotv = NaN(size(v));
%phase map
for i = 1:numel(x)
dotx(i) = v(i);
dotv(i) = -x(i); %<--- not sure about this!
end
close all;
figure;
quiver(x, v, dotx, dotv, 'red');
axis equal manual;
xlabel('x(t)');
ylabel('v(t)');
title('Harmonic Oscillator');
However, I'm not sure if the phase map part is correct. Comments / suggestions?
Thanks

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!