Matthew Daniel
Matthew Daniel

Reputation: 11

Julia - MethodError: no method matching current_axis(::Nothing)

I am trying to test a linear approximation function and I am getting the error "no method matching current_axis(::Nothing)".

Here is my linear approximation function:

function linear_approx(A,b,c,p0)
    p0 = [i for i in p0]
    y(p) = p'*A*p .+ b'*p .+ c .-1
    e = y(p0)
    d = 2*A*p0 + b
    (; d, e)
end

Here is the function that attempts to plot and throws an exception. I also included that value of the parameter when I tried to call it:

pts = [(1,1), (3,2), (4,4)]

function visualize_approx(pts)
    # Use this function to inspect your solution, and
    # ensure that the three points lie on one of 
    # the level-sets of your quadratic approximation.

    (; A, b, c) = constant_curvature_approx(pts)
    min_val = Inf
    max_val = -Inf
    for pt in pts
        (; d, e) = linear_approx(A,b,c,pt)
        P = LinRange(pt[1] - 0.2, pt[1]+0.2, 100)
        Q = linear_segment(pt, d, e, P)

        # the error arises here
        plot!(P, Q)

        plot!([pt[1]], [pt[2]])
    end
    delta = max_val - min_val
    min_val -= 0.25*delta
    max_val += 0.25*delta

    X = Y = LinRange(min_val,max_val, 100)
    Z = zeros(100,100)
    for i = 1:100
        for j = 1:100
            pt = [X[i]; Y[j]]
            Z[i,j] = pt'*A*pt + pt'*b + c
        end
    end
    contour(X,Y,Z,levels=[-1,0,1,2,3])
    for pt in pts
        plot!([pt[1]], [pt[2]])
    end
    current_figure()
end

Does anyone know why this error arises?

Upvotes: 0

Views: 323

Answers (1)

flurble
flurble

Reputation: 1106

plot! modifies a previously created plot object. It seems like you did not create a plot before calling it. This is why you get the error. Use plot when creating the plot and plot! when modifying it.

Upvotes: 1

Related Questions