Alex
Alex

Reputation: 21

Why is inv() failing?

When I try and run the inv() function on the example from the Julia documentation (v1.0.3), I get an error. The code is as follows (straight from the docs):

julia> M = [2 5; 1 3]
2×2 Array{Int64,2}:
 2  5
 1  3

julia> N = inv(M)
ERROR: MethodError: objects of type Array{Float64,2} are not callable
Use square brackets [] for indexing an Array.

It does work with pinv(), but I get some extremely small floating point values. Any ideas why I can't get inv() to work for this extremely simple case?

Upvotes: 2

Views: 287

Answers (1)

fredrikekre
fredrikekre

Reputation: 10984

The error message suggests that you have previously defined a variable called inv which is a floating point matrix, and then try to use this matrix as a function, e.g.

julia> inv = rand(2, 2);

julia> M = [2 5; 1 3];

julia> inv(M)
ERROR: MethodError: objects of type Array{Float64,2} are not callable
Use square brackets [] for indexing an Array.

You can reach the inv function by restarting (and hence clearing the meaning of inv) or using the fully qualified name:

julia> import LinearAlgebra

julia> LinearAlgebra.inv(M)
2×2 Array{Float64,2}:
  3.0  -5.0
 -1.0   2.0

Upvotes: 1

Related Questions