How can I simulate a demand with trend and seasonality

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 9 Dic 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 Commenti
Image Analyst
Image Analyst il 10 Dic 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. 🙂

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by