Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unworking slider

I would like to know whevery thing is displayed but the slider doesn't work.

var('x') # ne pas oublier de définir une variable avant de l'utiliser.
f(x) = (3/2) - (1/2)*x
g(x) = (11/2) - 2*x
h(x) = -1 + x
gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$')
gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\\frac{11}{2} - 2x$')
gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$')
gr.axes_labels(['$x_1$','$x_2$'])
fs1=solve(f(x) == h(x), x)
fs2=solve(f(x) == g(x), x)
fs3=solve(f(x) == 0, x)
gs1=solve(g(x) == h(x), x)
gs2=solve(g(x) == f(x), x)
gs3=solve(g(x) == 0, x)
hs1=solve(h(x) == 0,x)
pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),
      (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))]
c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint]
poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75))

@interact
def _(z=slider(0,(4/9),step_size=1/3)):
    if x!=fs1[0].rhs():
        zplot=plot(z - (1/3) *x, (x, 0,5),color="#4b26ea",linestyle='-.')
        show(sum(c)+gr+poly+zplot,figsize=8)
    elif x==gs2[0].rhs():
        zplot=plot(z - (1/3) *x, (x, 0,5),color="#4b26ea",linestyle='--')    
        show(sum(c)+gr+poly+zplot,figsize=8)

Unworking slider

I changed the question. This slider seems to work perfectly to the point that it never stop exactly on gs2[0]. I wonder why. It' borring since I would like to know whevery thing add some dash lines and commentary (labels, values..) in the cas where it is displayed but the slider doesn't work.exactly at this value.

var('x') # ne pas oublier de définir une variable avant de l'utiliser. f(x) = (3/2) - (1/2)*x (1/2)x g(x) = (11/2) - 2*x 2x h(x) = -1 + x gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$') color="#4b59ea",legend_label='$f(x)=\frac{3}{2} - \frac{1}{2}x$') gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\\frac{11}{2} color="#e52411",legend_label='$g(x)=\frac{11}{2} - 2x$') gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$') gr.axes_labels(['$x_1$','$x_2$']) fs1=solve(f(x) == h(x), x) fs2=solve(f(x) == g(x), x) fs3=solve(f(x) == 0, x) gs1=solve(g(x) == h(x), x) gs2=solve(g(x) == f(x), x) gs3=solve(g(x) == 0, x) hs1=solve(h(x) == 0,x) pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())), (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))] c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint] poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75)) show(pint) @interact def _(z=slider(0,(4/9),step_size=1/3)): _(z=slider(gs2[0].rhs()-(100.333333),gs2[0].rhs()+(50.333333),step_size=0.333333)): if x!=fs1[0].rhs(): zplot=plot(z - (1/3) (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.') show(sum(c)+gr+poly+zplot,figsize=8) elif x==gs2[0].rhs(): zplot=plot(z - (1/3) (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--') show(sum(c)+gr+poly+zplot,figsize=8)


show(sum(c)+gr+poly+zplot,figsize=8)

(gs2[0].rhs(),g(gs2[0].rhs()))

Unworking slider

I changed the question. This slider seems to work perfectly to the point that it never stop exactly on gs2[0]. I wonder why. It' borring since I would like to add some dash lines and commentary (labels, values..) in the cas where it is exactly at this value.

var('x') # ne pas oublier de définir une variable avant de l'utiliser. f(x) = (3/2) - (1/2)x g(x) = (11/2) - 2x h(x) = -1 + x gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\frac{3}{2} - \frac{1}{2}x$') gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\frac{11}{2} - 2x$') gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$') gr.axes_labels(['$x_1$','$x_2$']) fs1=solve(f(x) == h(x), x) fs2=solve(f(x) == g(x), x) fs3=solve(f(x) == 0, x) gs1=solve(g(x) == h(x), x) gs2=solve(g(x) == f(x), x) gs3=solve(g(x) == 0, x) hs1=solve(h(x) == 0,x) pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())), (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))] c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint] poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75)) show(pint) @interact def _(z=slider(gs2[0].rhs()-(100.333333),gs2[0].rhs()+(50.333333),step_size=0.333333)): if x!=fs1[0].rhs(): zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.') show(sum(c)+gr+poly+zplot,figsize=8) elif x==gs2[0].rhs(): zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--')
show(sum(c)+gr+poly+zplot,figsize=8)

(gs2[0].rhs(),g(gs2[0].rhs()))

Unworking sliderThis slider never stops on the optimal vertex of the feasible region

I changed the question. This slider seems to work perfectly to the point that it never stop exactly on gs2[0]. I wonder why. It' borring since I would like to add some dash lines and commentary (labels, values..) in the cas where it is exactly at this value.

var('x') # ne pas oublier de définir une variable avant de l'utiliser.

var('x')
f(x) = (3/2) - (1/2)x
(1/2)*x
g(x) = (11/2) - 2x
2*x
h(x) = -1 + x
gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\frac{3}{2} - \frac{1}{2}x$')
color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$')
gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\frac{11}{2} color="#e52411",legend_label='$g(x)=\\frac{11}{2} - 2x$')
gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$')
gr.axes_labels(['$x_1$','$x_2$'])
fs1=solve(f(x) == h(x), x)
fs2=solve(f(x) == g(x), x)
fs3=solve(f(x) == 0, x)
gs1=solve(g(x) == h(x), x)
gs2=solve(g(x) == f(x), x)
gs3=solve(g(x) == 0, x)
hs1=solve(h(x) == 0,x)
pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),
      (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))]
c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint]
poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75))
show(pint)
@interact
def _(z=slider(gs2[0].rhs()-(100.333333),gs2[0].rhs()+(50.333333),step_size=0.333333)):
_(z=slider(gs2[0].rhs()-(10*0.333333),gs2[0].rhs()+(5*0.333333),step_size=0.333333)):
    if x!=fs1[0].rhs():
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.')
        show(sum(c)+gr+poly+zplot,figsize=8)
    elif x==gs2[0].rhs():
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--') 
show(sum(c)+gr+poly+zplot,figsize=8)

(gs2[0].rhs(),g(gs2[0].rhs()))

show(sum(c)+gr+poly+zplot,figsize=8)

This slider never stops on the optimal vertex of the feasible region

I changed the question. This slider seems to work perfectly to the point that it never stop exactly on theline doesnt change its aspect in gs2[0]z1. I wonder why. why? It' borring since I would like to add some dash lines and commentary (labels, values..) in the cas where it is exactly at this value.

var('x')

var('x') # ne pas oublier de définir une variable avant de l'utiliser. f(x) = (3/2) - (1/2)*x (1/2)x g(x) = (11/2) - 2*x 2x h(x) = -1 + x gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$') color="#4b59ea",legend_label='$f(x)=\frac{3}{2} - \frac{1}{2}x$') gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\\frac{11}{2} color="#e52411",legend_label='$g(x)=\frac{11}{2} - 2x$') gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$') gr.axes_labels(['$x_1$','$x_2$']) fs1=solve(f(x) == h(x), x) fs2=solve(f(x) == g(x), x) fs3=solve(f(x) == 0, x) gs1=solve(g(x) == h(x), x) gs2=solve(g(x) == f(x), x) gs3=solve(g(x) == 0, x) hs1=solve(h(x) == 0,x) pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())), (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))] c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint] poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75)) show(pint) z1=solve(f(gs2[0].rhs())==z - (0.3333) gs2[0].rhs(),z)[0].rhs() @interact def _(z=slider(gs2[0].rhs()-(10*0.333333),gs2[0].rhs()+(5*0.333333),step_size=0.333333)): _(z=slider(z1-(50.1),z1+(5*0.1),step_size=0.333333)): if x!=fs1[0].rhs(): z!=z1: zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.') show(sum(c)+gr+poly+zplot,figsize=8) elif x==gs2[0].rhs(): z==z1: zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--') show(sum(c)+gr+poly+zplot,figsize=8)


show(sum(c)+gr+poly+zplot,figsize=8)

This slider never stops on the optimal vertex of the feasible region

I changed the question. This slider seems to work perfectly to the point that it theline doesnt change its aspect in z1. I wonder why? It' borring since I would like to add some dash lines and commentary (labels, values..) in the cas where it is exactly at this value.

 var('x') # ne pas oublier de définir une variable avant de l'utiliser.
f(x) = (3/2) - (1/2)x
(1/2)*x
g(x) = (11/2) - 2x
2*x
h(x) = -1 + x
gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\frac{3}{2} - \frac{1}{2}x$')
color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$')
gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\frac{11}{2} color="#e52411",legend_label='$g(x)=\\frac{11}{2} - 2x$')
gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$')
gr.axes_labels(['$x_1$','$x_2$'])
fs1=solve(f(x) == h(x), x)
fs2=solve(f(x) == g(x), x)
fs3=solve(f(x) == 0, x)
gs1=solve(g(x) == h(x), x)
gs2=solve(g(x) == f(x), x)
gs3=solve(g(x) == 0, x)
hs1=solve(h(x) == 0,x)
pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),
      (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))]
c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint]
poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75))
show(pint)
z1=solve(f(gs2[0].rhs())==z - (0.3333) gs2[0].rhs(),z)[0].rhs()
*gs2[0].rhs(),z)[0].rhs()
@interact
def _(z=slider(z1-(50.1),z1+(5*0.1),step_size=0.333333)):
_(z=slider(z1-(5*0.1),z1+(5*0.1),step_size=0.333333)):
    if z!=z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.')
        show(sum(c)+gr+poly+zplot,figsize=8)
    elif z==z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--') 
show(sum(c)+gr+poly+zplot,figsize=8)

show(sum(c)+gr+poly+zplot,figsize=8)

This slider never stops on the optimal vertex of the feasible region

I changed the question. This slider seems to work perfectly to the point that it theline doesnt change its aspect in z1. I wonder why? It' borring since I would like to add some dash lines and commentary (labels, values..) in the cas where it is exactly at this value.

  var('x') # ne pas oublier de définir une variable avant de l'utiliser.
f(x) = (3/2) - (1/2)*x
g(x) = (11/2) - 2*x
h(x) = -1 + x
gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$')
gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\\frac{11}{2} - 2x$')
gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$')
gr.axes_labels(['$x_1$','$x_2$'])
fs1=solve(f(x) == h(x), x)
fs2=solve(f(x) == g(x), x)
fs3=solve(f(x) == 0, x)
gs1=solve(g(x) == h(x), x)
gs2=solve(g(x) == f(x), x)
gs3=solve(g(x) == 0, x)
hs1=solve(h(x) == 0,x)
pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),
      (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))]
c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint]
poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75))
show(pint)
z1=solve(f(gs2[0].rhs())==z - (0.3333) *gs2[0].rhs(),z)[0].rhs()
@interact
def _(z=slider(z1-(5*0.1),z1+(5*0.1),step_size=0.333333)):
    if z!=z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.')
        show(sum(c)+gr+poly+zplot,figsize=8)
    elif z==z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--')    
        show(sum(c)+gr+poly+zplot,figsize=8)

This slider never stops on the optimal vertex Special-case a particular value of the feasible regionan interact slider

I changed the question. This slider seems to work perfectly to with one exception: the point that it theline doesnt line does not change its aspect in when z is exactly z1. .

I wonder why? It' borring It is annoying since I would like to add add some dash dashed lines and commentary comments (labels, values..) values...) in the cas where case it is exactly at this value.

  var('x') # ne pas oublier de définir une variable avant de l'utiliser.
f(x) = (3/2) - (1/2)*x
g(x) = (11/2) - 2*x
h(x) = -1 + x
gr = plot(f(x), (x, 0, 3),thickness=1.5, color="#4b59ea",legend_label='$f(x)=\\frac{3}{2} - \\frac{1}{2}x$')
gr+= plot(g(x), (x, 0, 3),thickness=1.5, color="#e52411",legend_label='$g(x)=\\frac{11}{2} - 2x$')
gr+= plot(h(x), (x, 0, 3),thickness=1.5, color="#2ea012",legend_label='$h(x)=-1 + x$')
gr.axes_labels(['$x_1$','$x_2$'])
fs1=solve(f(x) == h(x), x)
fs2=solve(f(x) == g(x), x)
fs3=solve(f(x) == 0, x)
gs1=solve(g(x) == h(x), x)
gs2=solve(g(x) == f(x), x)
gs3=solve(g(x) == 0, x)
hs1=solve(h(x) == 0,x)
pint=[(0,f(0)),(fs1[0].rhs(),f(fs1[0].rhs())),(fs2[0].rhs(),f(fs2[0].rhs())),(fs3[0].rhs(),f(fs3[0].rhs())),(0,g(0)),(gs1[0].rhs(),g(gs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),
      (gs3[0].rhs(),g(gs3[0].rhs())),(0,h(0)),(hs1[0].rhs(),h(hs1[0].rhs()))]
c=[circle(x, .05,fill=true,edgecolor='#ff9933', facecolor='#ff9933') for x in pint]
poly=polygon2d([(hs1[0].rhs(),h(hs1[0].rhs())),(fs1[0].rhs(),f(fs1[0].rhs())),(gs2[0].rhs(),g(gs2[0].rhs())),(gs3[0].rhs(),g(gs3[0].rhs()))],fill=true,rgbcolor=(.75,.75,.75))
show(pint)
z1=solve(f(gs2[0].rhs())==z - (0.3333) *gs2[0].rhs(),z)[0].rhs()
@interact
def _(z=slider(z1-(5*0.1),z1+(5*0.1),step_size=0.333333)):
    if z!=z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='-.')
        show(sum(c)+gr+poly+zplot,figsize=8)
    elif z==z1:
        zplot=plot(z - (0.3333) *x, (x, 0,5),color="#4b26ea",linestyle='--')    
        show(sum(c)+gr+poly+zplot,figsize=8)