Search code examples
ranalyticshierarchical

R- Equation with additional condition. Vector condition


I've got a problem with computing some expression like this:

equation

I tried use solve function but it shows me matrix must be n x n size. If someone encountered similar problem please help me or give some sources ;)


Solution

  • While this is in SAS, you should be able to adapt the concept. When trying to solve the equation, I receive the error:

    proc model;
        endo w1 w2 w3;
    
        w1 + 2*w2 + 8*w3 = 3.9167*w1;
        (1/2)*w1 + w2 + (1/4)*w3 = 3.9167*w2;
        (1/8)*w1 + 4*w2 + w3 = 3.9167*w3;
        w1 + w2 + w3 = 1;
    
        solve;
    quit;
    

    ERROR: The system of equations cannot be solved because it contains one or more overdetermined components with more equations, 4, than solve variables, 3.

    Which is expected, because we have 4 equations and 3 unknowns. One of the equations is redundant.

    Instead, let's consider this a system of three equations with a constraint, thus turning it into an optimization/simulation problem. We want to find w1, w2, w3 such that all equations are satisfied, with a constraint that w1 + w2 + w3 = 1.

    proc model;
        endo w1 w2 w3;
    
        w1 + 2*w2 + 8*w3 = 3.9167*w1;
        (1/2)*w1 + w2 + (1/4)*w3 = 3.9167*w2;
        (1/8)*w1 + 4*w2 + w3 = 3.9167*w3;
    
        restrict w1 + w2 + w3 = 1;
    
        solve / optimize printall;
    quit;
    

    Solution Details