How can I simulate a demand with trend and seasonality

3 views (last 30 days)
Hi,
For a project I would like to simulate a demand with Matlab, I'm still quite new to matlab and I don't know how to do this. I know how to make random numbers from a certain distribution but now I would like to add seasonality and a trend to the demand.
I would like to simulate a demand like the figure below. Are there any toolboxes or commands that can help me to do this?

Accepted Answer

Image Analyst
Image Analyst on 9 Dec 2021
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
numPoints = 61;
period = 1;
% Create time axis.
t = linspace(2011, 2016, numPoints);
% Create a linear ramp which will raise the signal over time.
ramp = linspace(2400, 3700, numPoints);
% Create noise to add to the signal.
noiseAmplitude = 300;
noise = noiseAmplitude * (rand(1, numPoints) - 0.5); % Range is -300/2 to +300/2
% Define the signal amplitude (as if there were no noise).
signalAmplitude = 400;
% Create final demand signal.
demand = ramp + signalAmplitude * sin(2 * pi * t / period) + noise;
% Plot signal.
plot(t, demand, 'k.-', 'LineWidth', 2, 'MarkerSize', 30);
% Plot ramp.
hold on; % Don't blow away signal. Keep siganl line showing.
plot(t, ramp, 'b-', 'LineWidth', 2)
grid on;
title('Demand vs. Time', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Demand', 'FontSize', fontSize);
xticks(2011:2016)
g = gcf;
g.WindowState = 'maximized'
  2 Comments
Image Analyst
Image Analyst on 10 Dec 2021
@Sem Albers I'm glad my code worked for you. Could you then click the "Accept this answer" link for me? Thanks in advance. 🙂

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!