Ask Your Question

interact variable not found

asked 2020-12-13 14:05:35 -0600

cybervigilante gravatar image

I keep getting ValueError: Variable 'h' not found when I try to plot an interact:

    f = (x-h)^2 - 4*a*(y-k)
    Parabola = solve(f,y)[0].rhs()
    def _(h=slider(-5,5,default=1), a=slider(-5,5,default=1), k=slider(-5,5,default=1)):

It even creates the sliders but the plot can't see h. What am I doing wrong? print(Parabola)image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-12-13 16:53:21 -0600

Juanjo gravatar image

updated 2020-12-13 16:54:12 -0600

This works for me:

f = (x-h)^2 - 4*a*(y-k)
Parabola = y.subs(solve(f,y))
def _(h=slider(-5,5,default=1), a=slider(-5,5,default=1),
    if a==0: 
        print("Invalid value for a. Please, select another value")

Parabola is a symbolic expression which depends on x, but also on a, h and k. You must explicitly substitute the values of these variables in Parabola before plotting it as a function of x. Please, also note the alternative way to define Parabola and the caution that should be taken in the case a=0.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-12-13 14:05:35 -0600

Seen: 28 times

Last updated: Dec 13 '20