Question

**Question 2.** CODING "FOR" LOOPS IN Rstudio Forecasts of the number of items purchased in the...

**Question 2.** CODING "FOR" LOOPS IN Rstudio

Forecasts of the number of items purchased in the future are desired, and the model to be used is (schematically):

`N[t] = round( 0.75*N[t-1] + sqrt(N[t-2]) + log10(1+N[t-3]) )`

In other words, the forecast purchases today is 3/4 the purchases observed yesterday plus the square root of the purchases the day before that plus the log10 of the one plus the number purchases before that (rounded to the nearest integer after the sum is taken).

Let the three most recently observed number of purchases be 7, 12, and 22 (a vector called `N` is created in the chunk below to store these). Using the forecasting equation, write a "for" loop to fill in elements 4-20 of `N` (these will represent the forecasted purchases for the next 17 days). Print out the contents of `N` to the screen once you are finished. You'll notice that eventually, the same number is forecast in-finitum (this is typical of forecasting models that don't explicitly put in a trend).

Homework Answers

Answer #1

Hi dear

As there's nothing specifically written about what coding language to use. So i'm using c code.

Hope it helps.

Code:-

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
float N[20];
N[1]=7; //initialisation
N[2]=12; //initialisation
N[3]=22; //initialisation
int i=0;
int j=1;
for(i=4;i<20;i++)
{
N[i] = round( 0.75*N[i-1] + sqrt(N[i-2]) + log(1+ N[i-3]) );   
}
  
for(j=1;j<20;j++)
{
printf("%f\n",N[j]);
}
  
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT