How can I simulate a demand with trend and seasonality
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sem Albers
el 9 de Dic. de 2021
Comentada: Image Analyst
el 10 de Dic. de 2021
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 comentario
Sankarshan Durgaprasad
el 9 de Dic. de 2021
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.
Respuesta aceptada
Image Analyst
el 9 de Dic. de 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 comentarios
Image Analyst
el 10 de Dic. de 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. 🙂
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!