I wonder if it mostly depends on what version of gcc/glibc MW used to compiled a particular version....
Dmitri.


I confirm all NaNs for the example in comment #9

I also get the allnanswithzeroinlowerright result on 2008b. But strangely on 2014a, I get all nans:

Rik,And you thought you could not have it both ways:
>> inv (repmat (Inf, [2,2]))
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND =
NaN.
ans =
NaN NaN
NaN 0
>> version
ans =
'9.3.0.713579 (R2017b)'
>>

The number of corner cases is just ridiculous. What does Matlab return for
I'm guessing it is either all zeros or all NaNs.

>> inv (complex (0,0))
Warning: Matrix is singular to working precision.
ans =
Inf
>> version
ans =
'9.3.0.713579 (R2017b)'
>>

@Colin: Can you check this corner case?
In Octave the result is strange
I think better thing would be to do automatic narrowing before calling inv() so that the result would be Inf.

Yes your guess is correct: Matlab gives the 2x2 matrix of Infs.

Another test case that needs to be run through Matlab
In Octave, this produces a special Diagonal matrix with Inf only on the diagonal.
On the other hand, my guess is that Matlab will return all Inf as in

I stepped through the code in dMatrix.cc and in fact the MatrixType is set to Diagonal for the case of a scalar. It looks like the general question is why there isn't an early decision to take care of diagonal matrices which would be very easy
Find attached a quick test (inv.diff). It seems to pass "make check" with no problems. To be complete there should also be some BIST tests for the correct behavior of scalars of all types (double, single, double complex, single complex) with respect to the various operations '1 / x', 'inv (x)', x^1, 'pinv (x)'.
(file #42320)

The problem is around line 646 of dMatrix.cc. If the condition number is zero, any result is set Inf, except for the (numel() == 1 ) case. What was the purpose of such an explicit exclusion?
I have a more general question: why a scalar is treated as a full matrix and not (at least) as a triangular matrix?

There have been some previous reports on this.
See bug #49690: inv(inf) behaves differently from inf^1, 1/inf, inf\1
See bug #51246: pinv(0) different from Matlab
As of 10/26/17 and hg id 857b553177a5, I get
The only problem is 'inv (0)'.

Another edge case:
That should be 0.

That should be "Inf" (e.g., in 4.2.1).
I think it changed sometime in the last few months but I have not bisected it yet to be sure.
