
How to simulate the number of ice-creams sold per hour ?
1 view (last 30 days)
Show older comments
Jabir Al Fatah
on 2 Jun 2014
Commented: Jabir Al Fatah
on 3 Jun 2014
I have the following code and I need to adjust the value of Am, B and D so that the cosine function shows the 1st and 24th rows are roughly equal to 50 and 12th row is roughly equal to 5. Now I have played with the values more than 100 times but none of them meets the condition.
Am=20;%Amplitude, play with the value
B=6;%Frequency,play with the value
C=0;%Phase, the phase's value is constant, it won't be changed
D=14;%Offset, play with the value
for j=1:7;%makes 7 columns
for i=1:24;%makes 24 rows
A(i,j)=Am*cos(B*i+C)+D
end
end
surf(A)%plots a cosine curve
[NOTE: The 24 rows represents the 24 hours (first row is 12 o'clock at noon) and 7 columns represents the 7 days in a week. The requirement is : Simulate the number of icecreams sold per hour during one week in a particular store in a warm summer week. We accept fractional number of icecreams ! Suppose that a icecream store sells about 50 icecreams per hour at noon, and about 5 icecreams per hour at midnight. Lets have a random fluctuation of about +/- 2 icecreams per hour. Lets start by assuming that every weekday has the same icecream sales.]
0 Comments
Accepted Answer
Image Analyst
on 2 Jun 2014
Hint: Try this:
clc
Am = 45/2;%Amplitude, play with the value
period = 24;%Frequency,play with the value
phase = 12;%Phase, the phase's value is constant, it won't be changed
offset = 5;%Offset, play with the value
theHour = 1:24; %makes 24 rows
A = Am * (1 + cos(2*pi*(theHour+phase)/period)) + offset
plot(A, 'bs-', 'LineWidth', 3)%plots a cosine curve
grid on;
xlim([1, 24]);
ylim([0, 55]);

Try adding noise (variation in # sales) with the rand() function.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!