bugGNU Octave - Bugs: bug #60839, Better document that `mldivide`...

 
 

bug #60839: Better document that `mldivide` and `mrdivide` might return minimum norm solutions

Submitted by:  None
Submitted on:  Sun 27 Jun 2021 06:36:50 PM UTC  
 
Category:  Documentation Severity:  2 - Minor
Priority:  3 - Low Item Group:  Documentation
Status:  Fixed Assigned to:  None
Originator Name:  Jose Luis Nuñez Crespi Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  6.2.0
Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 28 Jun 2021 08:38:05 AM UTC, comment #4: 

I added that sentence (and a link to `linsolve` from `mldivide`) here:
https://hg.savannah.gnu.org/hgweb/octave/rev/290eff7148bb

Closing as fixed.

Markus Mützel <mmuetzel>
Project Member
Mon 28 Jun 2021 07:00:06 AM UTC, comment #3: 

I was opening the documentation browser with `doc linsolve` in Octave 6.2.92 and clicked on the `mldivide` link in the "see also" section which led me to:

>> x \ y
>>   Left division. This is conceptually equivalent to the expression
>>     inv (x) * y
>>   but it is computed without forming the inverse of x.
>>   If the system is not square, or if the coefficient matrix is singular, a minimum norm solution is computed.


But I now see the docstring you are showing further down on the same page.

We could probably repeat the last sentence above in the docstrings of `mldivide` and `mrdivide`.

Re-opening with category "Documentation".

Markus Mützel <mmuetzel>
Project Member
Mon 28 Jun 2021 06:49:56 AM UTC, comment #2: 

It looks like the help has changed.
With current stable (GNU Octave Version: 6.2.93 (hg id: 340d6d3dcc94) I see:

octave:1> help mldivide
'mldivide' is a built-in function from the file libinterp/corefcn/data.cc

-- mldivide (X, Y)
     Return the matrix left division of X and Y.

     This function and X \ Y are equivalent.

     See also: mrdivide, ldivide, rdivide.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 28 Jun 2021 06:43:19 AM UTC, comment #1: 

See the documentation for `linsolve`:

>> With no options, this function is equivalent to the left division operator (x = A \ b) or the matrix-left-divide function (x = mldivide (A, b)).
>> The optional second output R is the inverse condition number of A (zero if matrix is singular).


And the documentation for `mldivide`:

>> If the system is not square, or if the coefficient matrix is singular, a minimum norm solution is computed.


So what you are seeing is the expected result afaict.

You could check the second output argument of `linsolve` to query whether the input matrix is singular.
For your example:

>> [S, R] = linsolve([1.000,-1.000,1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;-1.000,-1.000,1.000,1.000,-1.000;-1.000,-1.000,1.000,-1.0
00,-1.000],[-1.000;-1.000;1.000;1.000;1.000])
warning: matrix singular to machine precision
warning: called from
    linsolve at line 113 column 7

S =

  -1.0000e+00
  -2.5000e-01
  -5.0000e-01
  -2.5622e-16
  -2.5000e-01

R = 0

Markus Mützel <mmuetzel>
Project Member
Sun 27 Jun 2021 06:36:50 PM UTC, original submission:  

I have written a set of libraries in Java to deal with complex numbers with several mathematical functions and arithmetic capablities.

I use GNU Octave, Maxima and sometimes Wolfram to check the results returned from my progrmas.

In one of the tests I use the following system that is inconsistent
+(1)x0+(-1)x1+(1)x2+(1)x3+(-1)x4 = -1
+(1)x0+(-1)x1+(-1)x2+(1)x3+(-1)x4 = -1
+(1)x0+(-1)x1+(-1)x2+(1)x3+(-1)x4 = 1
+(-1)x0+(-1)x1+(1)x2+(1)x3+(-1)x4 = 1
+(-1)x0+(-1)x1+(1)x2+(-1)x3+(-1)x4 = 1

But Octave returns the following result, and I think that is incorrect, maybe the warnings invalidate the result returned...

>> disp(Sol = linsolve([1.000,-1.000,1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;-1.000,-1.000,1.000,1.000,-1.000;-1.000,-1.000,1.000,-1.000,-1.000],[-1.000;-1.000;1.000;1.000;1.000]))

warning: matrix singular to machine precision
warning: called from
    linsolve at line 113 column 7

  -1.0000e+00
  -2.5000e-01
  -5.0000e-01
  -2.2204e-16
  -2.5000e-01

>> rank([1.00,-1.00,1.00,1.00,-1.00;1.00,-1.00,-1.00,1.00,-1.00;1.00,-1.00,-1.00,1.00,-1.00;-1.00,-1.00,1.00,1.00,-1.00;-1.00,-1.00,1.00,-1.00,-1.00])

ans = 4

>> rank([1.00,-1.00,1.00,1.00,-1.00;1.00,-1.00,-1.00,1.00,-1.00;1.00,-1.00,-1.00,1.00,1.00;-1.00,-1.00,1.00,1.00,1.00;-1.00,-1.00,1.00,-1.00,1.00])

ans = 5

The answer given from Maxima for the same system is

(%i1) expand(linsolve([+(1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(-1.000)*x3+(-1.000)*x4=1.000],[x0,x1,x2,x3,x4]));
(%o1) []

And from my java program (https://github.com/ipserc/complexarith TestSyseq1.java)

#===============================================================#
I                                                               I
I                 LINEAR EQUATIONS SYSTEM TEST                  I
I                                                               I
#===============================================================#
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:                        Equation System                        :
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+(1.000)x0+(-1.000)x1+(1.000)x2+(1.000)x3+(-1.000)x4 = -1.000
+(1.000)x0+(-1.000)x1+(-1.000)x2+(1.000)x3+(-1.000)x4 = -1.000
+(1.000)x0+(-1.000)x1+(-1.000)x2+(1.000)x3+(-1.000)x4 = 1.000
+(-1.000)x0+(-1.000)x1+(1.000)x2+(1.000)x3+(-1.000)x4 = 1.000
+(-1.000)x0+(-1.000)x1+(1.000)x2+(-1.000)x3+(-1.000)x4 = 1.000
The system is INCONSISTENT
+---------------------------------------------------------------+
|                     System Solve Commands                     |
+---------------------------------------------------------------+
MComplex:new MatrixComplex("1.000,-1.000,1.000,1.000,-1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000,1.000;-1.000,-1.000,1.000,1.000,-1.000,1.000;-1.000,-1.000,1.000,-1.000,-1.000,1.000")
MAXIMA:expand(linsolve([+(1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(-1.000)*x3+(-1.000)*x4=1.000],[x0,x1,x2,x3,x4]))
OCTAVE:disp(Sol = linsolve([1.000,-1.000,1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;1.000,-1.000,-1.000,1.000,-1.000;-1.000,-1.000,1.000,1.000,-1.000;-1.000,-1.000,1.000,-1.000,-1.000],[-1.000;-1.000;1.000;1.000;1.000]))
WOLFRAM:solve(+(1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=-1.000,+(1.000)*x0+(-1.000)*x1+(-1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(1.000)*x3+(-1.000)*x4=1.000,+(-1.000)*x0+(-1.000)*x1+(1.000)*x2+(-1.000)*x3+(-1.000)*x4=1.000,x0,x1,x2,x3,x4)
#===============================================================#
|                       System Solutions                        |
#===============================================================#
There are no solutions for an INCONSISTENT Equation System

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-06-28 mmuetzel StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2021-06-28 mmuetzel CategoryOctave Function => Documentation
        Severity3 - Normal => 2 - Minor
        Priority5 - Normal => 3 - Low
        Item GroupIncorrect Result => Documentation
        StatusInvalid => Confirmed
        Open/ClosedClosed => Open
        Operating SystemGNU/Linux => Any
        Summarylinsolve returns an incorrect solution with an inconsistent system => Better document that `mldivide` and `mrdivide` might return minimum norm solutions
    2021-06-28 mmuetzel StatusNone => Invalid
        Open/ClosedOpen => Closed

    Back to the top


    Powered by Savane 3.7