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 件のコメント
Christopher
Christopher 2025 年 6 月 5 日
I was thinking in terms of timespan...
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 件のコメント
Christopher
Christopher 2025 年 6 月 5 日
Ok, use the same code to generate x2 and x3?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by