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

조회 수: 4 (최근 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