How do I exclude the first ten observations in the line plot generated by the three differential equations

3 次查看(过去 30 天)
close all
clear all
clc
tspan = [0 100];
y0 = 0.7; % initial value of state variable x1
r0 = 0.7; % initial value of state variable x2
w0 = 0.8; % initial value of state variable x3
x0 = [y0; r0; w0];
[t, x] = ode45(@odefcn, tspan, x0);
%% Plot x2 (y-axis) vs. x1 (x-axis)
subplot(3,1,1);
plot(t,x(:,1));
xlabel('Time')
ylabel('Output');
subplot(3,1,2);
plot(t,x(:,2));
xlabel('Time')
ylabel('Policy Rate');
subplot(3,1,3);
plot(t,x(:,3));
xlabel('Time')
ylabel('Wage Share');
y0 = [0.7; 0.7; 0.8];
%% System of three differential equations
function dx = odefcn(t, x)
% definitions
y = x(1);
r = x(2);
w = x(3);
% parameters
alpha = 1.0;
beta = 1.0;
gamma = 0.1;
delta = 0.3;
mu = 1.0;
lambda = 0.3;
theta = 0.1;
omega = 0.2;
% ODEs
dx(1,1) = alpha * y - beta * r * y;
dx(2,1) = - omega * r + gamma * w * r + delta * y * r;
dx(3,1) = - theta * w + lambda * y * w - mu * w * w;
end
  6 个评论
Torsten
Torsten 2025-6-5
It's still not clear what you mean.
If you define
tspan = [0 100];
ode45 will choose the output times between 0 and 100 on its own. Thus excluding the first ten outputs does not tell you anything about the time points when these ten outputs were reported: they could be [0 1 2 3 4 5 6 7 8 9] or any other increasing vector with 10 elements starting at 0.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2025-6-4
编辑:Matt J 2025-6-4
One way,
tspan = [0 100];
y0 = 0.7; % initial value of state variable x1
r0 = 0.7; % initial value of state variable x2
w0 = 0.8; % initial value of state variable x3
x0 = [y0; r0; w0];
[t, x] = ode45(@odefcn, tspan, x0);
x(1:10,:)=nan;
  6 个评论

请先登录,再进行评论。

类别

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

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by