plotting a phase plane with a system of linear diff equations.
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I have this system of differential equations(at the very bottom), and I'm not sure how to go about plotting a phase plane. Something that looks like the graph below.(This is just an example for another set of equations.)
syms u(t) v(t)
ode1 = diff(u) == ((1/40)*v)-(u*(9/100))
ode2 = diff(v) == (u*(9/100))-(v*(9/200))
0 个评论
采纳的回答
Star Strider
2021-7-28
Using the numeric ODE solvers, likely the easiest way to do that is to use odeset to set options, and then choose 'OutputFcn', @odephas2 as described in the documentation section on Solver Output .
syms u(t) v(t) t Y
ode1 = diff(u) == ((1/40)*v)-(u*(9/100))
ode2 = diff(v) == (u*(9/100))-(v*(9/200))
[VF,Sbs] = odeToVectorField(ode1,ode2)
ode12fcn = matlabFunction(VF, 'Vars',{t,Y})
% ic = randn(2,1)
ic = [-0.4 0.2]
[t,y] = ode45(ode12fcn,[0 100], ic);
for k = 1:numel(t)
dy(:,k) = ode12fcn(t(k),y(k,:));
end
figure
plot(y(:,1), y(:,2))
grid
xlabel('y_1')
ylabel('y_2')
figure
quiver(y(:,1), y(:,2), dy(1,:).',dy(2,:).')
grid
xlabel('y_1')
ylabel('y_2')
opts = odeset('OutputFcn', @odephas2);
figure
[t,y] = ode45(ode12fcn,[0 100], ic, opts);
figure
plot(t, y)
grid
xlabel('t')
ylabel('y')
legend(string(Sbs))
That is the essential approach.
I will defer to you for the rest.
.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!