Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Adding a extra variable to a model

Asked by Kevin van Berkel on 12 Jun 2013
 Hi guys,
    I have the following model:
        function [R_e, dp] = VAR_CRSP(M,T,r_f);
        epsilon = zeros(M,T,2);
        r = zeros(M,T);
        dp= zeros(M,T);
        for m=1:M
            epsilon(m,:,:,: ) = mvnrnd([0;0;0], [0.0012,-0.001;-0.001,0.0027],T)
        end
        for m=1:M
           dp0=-3.461;
           r(m,1) = 0.1161+0.060*dp0 + epsilon(m,1,1);
           dp(m,1)=-0.052+0.9702*dp0 + epsilon(m,1,2);
           for i = 1:T-1
               r(m,i+1) = 0.1161+0.060*dp(m,i) + epsilon(m,i+1,1);
               dp(m,i+1) = -0.052+0.9702*dp(m,i) + epsilon(m,i+1,2);
           end
        end
        end

Now i want to add a extra variable to the model. I did it as simply as this, but I don't think it's the correct way:

    function [R_e, dp] = VAR_CRSP(M,T,r_f);
    epsilon = zeros(M,T,3);
    r = zeros(M,T);
    dp= zeros(M,T);
    mom=zeros(M,T);
    for m=1:M
        epsilon(m,:,:,: ) = mvnrnd([0;0;0], [0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001],T)
    end
    for m=1:M
       dp0=-3.461;
       r(m,1) = 0.1161+0.060*dp0 + epsilon(m,1,1);
       dp(m,1)=-0.052+0.9702*dp0 + epsilon(m,1,2);
       mom(m,1)=-0.344+0.966*dp0 + epsilon(m,1,3);
       for i = 1:T-1
           r(m,i+1) = 0.1161+0.060*dp(m,i) + epsilon(m,i+1,1);
           dp(m,i+1) = -0.052+0.9702*dp(m,i) + epsilon(m,i+1,2);
           mom(m,i+1) = -0.533+0.931*dp(m,i) + epsilon(m,i+1,3); 
       end
    end
    R_e = r_f*exp(r)-r_f;
    end

My first error is:

    Error using mvnrnd (line 110)
    SIGMA must be a symmetric positive semi-definite matrix.
    Error in VAR_CRSP (line 9)
        epsilon(m,:,:,:) = mvnrnd([0;0;0], [0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001],T)

So anyone knows how to resolve this?

Many thanks in advance!!

0 Comments

Kevin van Berkel

Products

No products are associated with this question.

2 Answers

Answer by Matt J on 12 Jun 2013
Edited by Matt J on 12 Jun 2013
Accepted answer
    >> SIGMA=[0.0012,-0.001,0.0001;-0.001,0.0027,0.001;0.001,0.001,0.001];
    >> eig(SIGMA)
    ans =
       -0.0001
        0.0016
        0.0034

As you can see, your SIGMA matrix has a negative eigenvalue, and is therefore not positive semi-definite.

0 Comments

Matt J
Answer by Kevin van Berkel on 12 Jun 2013

Thanks Matt! Solved it.

0 Comments

Kevin van Berkel

Contact us