Push!() giving Method type error

p is of type Vector{Int} and you try to push! something like a Array{Float64,2} (p_0) into this array.

julia> p = [1]
1-element Vector{Int64}:
 1

Your code is not a MWE (minimal working example) so it’s not clear what p_0 is.
What is the output of print(typeof(p_0))?
For now a naiv solution can be not to initialize p as you do it, but e.g.:

function characteristic_polynomial(A)
    z = size(A)
    n = z[1]
    for i = 1:n
        p_0 = (-1)^i*sum(principal_minor(A,i))
        if ! @isdefined p
                p=Array{typeof(p_0)}(undef,0)
        end
        push!(p, p_0)
    end
    return p
end

This assumes that the type of p_0 is always the same.

1 Like