# bug #63082: eig(NaN) and eig(Inf) emit an error in Octave while Matlab returns NaN

 Submitter: Johannes Pfeifer Submitted: Tue 20 Sep 2022 10:16:25 AM UTC Category: Octave Function Severity: 2 - Minor Priority: 3 - Low Item Group: Matlab Compatibility Status: Confirmed Assigned to: None Originator Name: Johannes Pfeifer Open/Closed:  * Open Release:  * dev Operating System:  * Any Fixed Release: None Planned Release: None
* Mandatory Fields

Add a New Comment Rich Markup

## Discussion

Tue 20 Sep 2022 10:08:31 PM UTC, comment #4:

Confirmed.  I changed the Summary to reflect that this is merely a Matlab Compatibility difference.  In the cases I tried, Matlab always returns a vector of all NaNs whenever the input contains even one Inf or NaN value.

We could choose to make Octave do the same thing.  The code is in the directory liboctave/numeric/ and in the files EIG.cc and fEIG.cc.  There are four init() routines in each file which have a check similar to this one

if (a.any_element_is_inf_or_nan ())
(*current_liboctave_error_handler)
("EIG: matrix contains Inf or NaN values");

Rik <rik5>
Tue 20 Sep 2022 04:24:14 PM UTC, comment #3:

Sorry, the second one should be:

eig ([1, Inf; 0, 2])

ans =

NaN
NaN

Johannes Pfeifer <jpfeifer>
Tue 20 Sep 2022 04:22:58 PM UTC, comment #2:

For nonfinite matrices, the result in Matlab is a NaN-vector:

eig ([1, NaN; 0, 1])
ans =

NaN
NaN

and

eig ([1, NaN; 0, 1])

ans =

NaN
NaN

Johannes Pfeifer <jpfeifer>
Tue 20 Sep 2022 04:18:23 PM UTC, comment #1:

In Matlab, is this just a special case for scalar inputs?  What happens for things like

eig ([1, Inf; 0, 2])
eig ([1, NaN, 0, 1])

?

John W. Eaton <jwe>
Tue 20 Sep 2022 10:16:25 AM UTC, original submission:

In Matlab

eig(Inf)
+verbatim+
and
+verbatim+
eig(NaN)
+verbatim+
return NaN. In Octave, the code will instead crash with

> error: EIG: matrix contains Inf or NaN values

Johannes Pfeifer <jpfeifer>

## Attached Files

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

Attach Files:

Comment:

No files currently attached

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by rik5 (Posted a comment)
• -email is unavailable- added by jwe (Posted a comment)
• -email is unavailable- added by jpfeifer (Submitted the item)
•

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only group members can vote.