2013-03-01 114 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