2013-03-01 126 views
1
  1. Can Octave可以识别线性系统没有解决方案,并抛出一个消息的效果?
  2. Octave'Solve'线性系统有多种解决方案并描述解决方案集?

下面是对我无用的八度输出的两个例子。是否有另一种方法可以要求Octave获得所需的输出?Can Octave:解决线性系统有很多解决方案还是没有解决方案?

无解:

octave:13> A=[1,1,1;1,1,1] 
A = 
    1 1 1 
    1 1 1 

octave:14> b=[0;1] 
b =  
    0 
    1 

octave:15> A\b 
ans =  
    0.16667 
    0.16667 
    0.16667 

无穷多解:从(http://joshua.smcvt.edu/linearalgebra/book.pdf)2.13(PG16)拍摄的。

octave:19> M=[2,1,0,-1,0;0,1,0,1,1;1,0,-1,2,0] 
M = 
    2 1 0 -1 0 
    0 1 0 1 1 
    1 0 -1 2 0 

octave:20> n=[4;4;0] 
n =  
    4 
    4 
    0 

octave:21> M\n 
ans =  
    0.761905 
    2.380952 
    0.571429 
    -0.095238 
    1.714286 

Books Solution: 
{ [x;y;z;w;u] = 
    [0; 4; 0; 0; 0] + [1; -1; 3; 1; 0]*w + [0.5; -1; 0.5; 0; 1]*u | w,u (R) 
} 
OR 
{ (w+(0.5)u, 4-w-u, 3w+(0.5)u, w, u) | w,u (R) } 

回答

0

我不知道是否有任何内置在检查你想要的功能,但是对于你的第一个问题,但你可以编写代码来检查自己。你需要看看在将增广矩阵放入行减少梯队形式(rref)后是否发生了矛盾。你可以通过查看是否对于任何行来做到这一点,所有变量都是0,但常数不是0.这意味着0 * x1 + 0 * x2 + ... 0 * xn不等于零(矛盾)。相信下面的代码检查正是

%function [feasible, x] = isfeasible(A,b) 
%checks if Ax = b is feasible (a solution exists) 
%and returns the solution if it exits 
%input 
%A: M x N matrix representing the variables in each equation, with one equation per row 
%b: N X 1 vector of the constants 
%output 
%feasible: 1 if a solution exists, 0 otherwise 
%x: N x 1 vector containing the values of the variables 
function [feasible, x] = isfeasible(A,b) 
    feasible = 1; %assume function is feasible 
    Rref = rref([A,b]); %put the augmented matrix into row reduced echelon form 
    x = Rref(:,end); %these are the values that the variables should be to solve the set of equations 
    variableSums = sum(abs(Rref(:,1:(end-1))),2); 
    if(any((variableSums == 0) & (abs(x) ~= 0))) %a contradiction has occurred. 
    feasible = 0; %this means that 0 * all the variables is not 0 
    endif 
endfunction 

至于第二个问题,如果把增广矩阵[A,B]为行减小梯形形式之后的任何行具有超过1个柱(不包括最后一列)与一个非零值,那么你的方程组有多个解决方案。八度可以解决这个问题,并可以表征一套解决方案。你所要做的就是rref([A,b])并阅读你找回的解决方案。

在您的示例使用RREF我发现 RREF([M,N])=

 x   y   z   w   u  constant 
    1.00000 0.00000 0.00000 -1.00000 -0.50000 0.00000 
    0.00000 1.00000 0.00000 1.00000 1.00000 4.00000 
    0.00000 0.00000 1.00000 -3.00000 -0.50000 -0.00000 

这意味着

X = W + 0.5 * U

Y = 4 - w - u

z = 3 * w + .5 * u