Plotting trajectories of a system of equations.
Show older comments
Hi all,
Im writing a project and have been told that MatLab is the best way to visualise what is happening, however i am very new to matlab.
the two equations I wish to plot are simple, dx/dt = ax and dy\dt = -y. I want to vary a and then see how the phase portrait changes by plotting some trajectories and showing how the fixed point at the origin changes according to the value of a. I have solved the system having no problems but them when it comes to plotting anything i am having difficulties.
The code i have so far is:
syms x(t) y(t);
a=1;
A = [a 0; 0 1];
Z = [x;y];
odes = diff(Z) == A*Z
[xSol(t), ySol(t)] = dsolve(odes);
xSol(t) = simplify(xSol(t))
ySol(t) = simplify(ySol(t))
xdom = linspace(-10,10,100);
ydom = linspace(-10,10,100);
U = a.*x;
V = -1*y;
[X,Y] = meshgrid(xdom,ydom);
quiver(X,Y,U,V)
% this returns an error saying unable to conver expression into double array
Accepted Answer
More Answers (0)
Categories
Find more on Symbolic Math Toolbox 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!