How can I simulate a demand with trend and seasonality

3 ビュー (過去 30 日間)
Sem Albers
Sem Albers 2021 年 12 月 9 日
コメント済み: Image Analyst 2021 年 12 月 10 日
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?
  1 件のコメント
Sankarshan Durgaprasad
Sankarshan Durgaprasad 2021 年 12 月 9 日
This will give you a function for "Demand" you can use this function to get 365 points for 1 year and use a scaling factor for other years :)
Hope this helps.

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

採用された回答

Image Analyst
Image Analyst 2021 年 12 月 9 日
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 件のコメント
Sem Albers
Sem Albers 2021 年 12 月 10 日
Thank you so much it worked! :)
Image Analyst
Image Analyst 2021 年 12 月 10 日
@Sem Albers I'm glad my code worked for you. Could you then click the "Accept this answer" link for me? Thanks in advance. 🙂

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by