R- Equation with additional condition. Vector condition

时间:2016-03-04 18:07:48

标签: r analytics hierarchical

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 ;)

1 个答案:

答案 0 :(得分:-1)

虽然这是在SAS中,但您应该能够适应这一概念。在尝试解决方程时,我收到错误:

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;
  

错误:方程组无法解决,因为它包含   一个或多个超定组分,其中包含更多的方程,4   解决变量,3。

这是预期的,因为我们有4个方程和3个未知数。其中一个方程是多余的。

相反,我们将这个系统考虑为具有约束的三个方程组,从而将其转化为优化/模拟问题。我们希望找到w1w2w3,以便满足所有方程式,约束 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