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))

采纳的回答

Star Strider
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))
ode1(t) = 
ode2 = diff(v) == (u*(9/100))-(v*(9/200))
ode2(t) = 
[VF,Sbs] = odeToVectorField(ode1,ode2)
VF = 
Sbs = 
ode12fcn = matlabFunction(VF, 'Vars',{t,Y})
ode12fcn = function_handle with value:
@(t,Y)[Y(1).*(-9.0./2.0e+2)+Y(2).*(9.0./1.0e+2);Y(1)./4.0e+1-Y(2).*(9.0./1.0e+2)]
% ic = randn(2,1)
ic = [-0.4 0.2]
ic = 1×2
-0.4000 0.2000
[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);
Error using uicontrol
This functionality is not available on remote platforms.

Error in odephas2 (line 94)
uicontrol( ...

Error in ode45 (line 269)
feval(outputFcn,[t tfinal],y(outputs),'init',outputArgs{:});
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 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by