How do I exclude the first ten observations in the line plot generated by the three differential equations
Show older comments
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 Comments
Christopher
on 4 Jun 2025
Torsten
on 4 Jun 2025
You really mean the first ten outputs from ode45 or the outputs up to time t = 10 ?
Christopher
on 4 Jun 2025
I want to fit a trend line through the data excluding the first ten periods.
What are "periods" according to your definition ? According to what "period" usually means, your graphs only have 6 or 7 periods for tspan = [0 100] (counted as the number of minima/maxima of the plotted functions).
Christopher
on 5 Jun 2025
Torsten
on 5 Jun 2025
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.
Answers (1)
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 Comments
Steven Lord
on 4 Jun 2025
And once you've replaced the first ten points with NaN, consider using the detrend function, the trenddecomp function, or the Find and Remove Trends Live Editor Task.
Adam Danz
on 4 Jun 2025
Alternatively, if you'd like to preserve the initial 10 values,
plot(t(11:end),x(11:end,1));
Christopher
on 4 Jun 2025
@Christopher Cerainly it does. How Could it not? But see below:
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)
h=plot(t,x(:,1),'r', t(11:end),x(11:end,1),'b-'); xlim([0,25])
Christopher
on 5 Jun 2025
Matt J
on 5 Jun 2025
Yes, I would imagine.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
