Ask Your Question
0

Plot-region depending of the interacted value

asked 2020-04-08 21:03:13 +0100

Cyrille gravatar image

updated 2020-04-08 21:05:20 +0100

How to have the plot dependent of the solved value a. The following code conducts to an error

def _(c=slider(0,1,step_size=0.2,default=1)):

a = 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="yellow",ymin=0,ymax=10)

show(g+h)

edit retag flag offensive close merge delete

Comments

a = solve(-c*x+6==x, x) gives a list with an equation in it [x==(30/7)]. Use a[0].right() to get the value, which can then be used in a coordinate pair.

dazedANDconfused gravatar imagedazedANDconfused ( 2020-04-09 01:25:06 +0100 )edit

Thanks a lot

Cyrille gravatar imageCyrille ( 2020-04-09 08:00:59 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-04-09 01:01:35 +0100

Juanjo gravatar image

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)
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

Stats

Asked: 2020-04-08 21:03:13 +0100

Seen: 246 times

Last updated: Apr 09 '20