Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In your code, the variable a does not contain a numerical value, but the list yielded by solve. You need to extract the value of the solution, for example, with

a = x.subs(solve(-c*x+6==x, x))

In addition, when the slider takes the value c=0, then a=6. This causes a new error when computing the plot h, since the interval appearing there starts and ends with the same value. Finally, the yellow color is not , IMHO, a good choice, it is hardly visible.

The following code tries to solve these issues:

@interact
def _(c=slider(0.1,1,step_size=0.2,default=1)):
    a = x.subs(solve(-c*x+6==x, x))
    g = plot(x,(0,10),color="blue",ymin=0,ymax=10)
    h = plot(-c*x+6,(a,6),color="green",ymin=0,ymax=10)
    show(g+h)