MATLAB Answers

0

Successfully implement harmonic oscillator phase plot

Asked by Steve West on 30 Sep 2019 at 9:22
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

  0 Comments

Sign in to comment.

Products


Release

R2019a

0 Answers