Successfully implement harmonic oscillator phase plot

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

Réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by