Octave:解决线性系统有多种解决方案或没有解决方案?

时间:2013-03-01 21:49:09

标签: octave linear-algebra

  1. Octave能否使用NO解决方案识别线性系统,并发出相应的信息?
  2. Octave可以解决具有多种解决方案并描述解决方案集的线性系统吗?
  3. 这是Octave输出的两个例子,对我没用。有没有其他方法可以向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
    

    Infinity Many Solutions:取自(http://joshua.smcvt.edu/linearalgebra/book.pdf)2.13(第16页)。

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

1 个答案:

答案 0 :(得分: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列(不包括最后一列)的非零值,那么你的方程组有不止一个解决方案。 Octave可以解决这个问题,并可以表征这套解决方案。你所要做的就是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 + .5 * u

y = 4 - w - u

z = 3 * w + .5 * u

相关问题