Results 1 to 5 of 5

Math Help - Iteration in MATLAB

  1. #1
    Newbie
    Joined
    Jun 2008
    Posts
    9

    Iteration in MATLAB

    Hi!

    Just wondering if anyone would like to help me with this.

    I'd like to obtain 1000 samples each of 100 observations of the following autoregressive equation

    x(t+1) = a*x(t) + e(t+1)

    where x is some random variable and e is white noise. To do it once, you can write a for loop as follows:

    x(1) = 0
    for t = 1:100
    x(t+1)=a*x(t) + e(t+1)
    end

    That's fine. But how would I repeat the process 1000 times, each time with a different 100 observation sample for e and also have the x series from each sample stored?

    Cheers guys.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by bradbrad View Post
    Hi!

    Just wondering if anyone would like to help me with this.

    I'd like to obtain 1000 samples each of 100 observations of the following autoregressive equation

    x(t+1) = a*x(t) + e(t+1)

    where x is some random variable and e is white noise. To do it once, you can write a for loop as follows:

    x(1) = 0
    for t = 1:100
    x(t+1)=a*x(t) + e(t+1)
    end

    That's fine. But how would I repeat the process 1000 times, each time with a different 100 observation sample for e and also have the x series from each sample stored?

    Cheers guys.
    Code:
      sigma=1;
      x=zeros(100,1000);
      for t = 1:100
        x(t+1,:)=a*x(t,:) + sigma*randn(1,1000);
      end
    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2008
    Posts
    9
    Ron - Thank you very much for this.

    May I complicate it slightly?

    If x were now a vector of variables and e a vector of shocks assumed to be multivariate normal and correlated with each other, how would you obtain the 1000 samples each of 100 observations?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by bradbrad View Post
    Ron - Thank you very much for this.

    May I complicate it slightly?

    If x were now a vector of variables and e a vector of shocks assumed to be multivariate normal and correlated with each other, how would you obtain the 1000 samples each of 100 observations?
    Assuming that you have a function noise(N,Reps,sigma) which produces a row vector of length Reps each of who's elements is a column vector of dimension N which is multivariate normal with covariance matrix sigma:

    Code:
      nt=100; nx=4; nreps=1000
      sigma=[1, 0.1; 0.1, 1];
      x=zeros(nt,nx,nreps);
      for t = 1:nt
        x(t+1,:,:)=a*x(t,:,:) + noise(4,1000,sigma);
      end
    RonL
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jun 2008
    Posts
    9
    Thanks again. People like you make the world go round.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Gauss-Seidel iteration in Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: September 21st 2010, 11:37 PM
  2. Replies: 4
    Last Post: April 18th 2010, 03:54 PM
  3. fixed point iteration question with matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: March 7th 2010, 01:34 PM
  4. Replies: 0
    Last Post: May 7th 2009, 10:52 AM
  5. Replies: 3
    Last Post: January 25th 2009, 11:03 AM

Search Tags


/mathhelpforum @mathhelpforum