Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Implicitly : try someting along the lines of :

plot3d(U, (0, 2), (0, 2), color="blue", opacity=0.5) +\
plot3d(B, (0, 2), (0, 2), color="yellow", opacity=0.5) +\
plot3d(U, (0, 2), (0, 2), color="red", plot_points=100).add_condition(lambda t, u, v:abs(v-B(t, u))<0.02)

Labeling and other seasonings left to the reader...

An explicit solution is necessarily numeric...

HTH,

Implicitly : try someting along the lines of :

plot3d(U, (0, 2), (0, 2), color="blue", opacity=0.5) +\
plot3d(B, (0, 2), (0, 2), color="yellow", opacity=0.5) +\
plot3d(U, (0, 2), (0, 2), color="red", plot_points=100).add_condition(lambda t, u, v:abs(v-B(t, u))<0.02)

Labeling and other seasonings left to the reader...

An explicit solution is necessarily numeric...

HTH,

EDIT :

Using Python functions rather than callable symbolic expression is way faster. After running :

# Python version
x, y, z = var("x, y, z")
# U(x,y) = x^(1/2)*y^(1/2)
# B(x,y) = (1/16)*x + y
def U(a, b): return sqrt(a)+sqrt(b)
def B(a, b): return a/16+b
def lu(e): return lambda a, b, c: abs(c-B(a, b))<=e
def lb(e): return lambda a, b, c: abs(c-U(a, b))<=e
def doit(e = 0.01, show_u = True,show_b = True, pp = 40, ppc = 100):
    if show_u: cu = lu(e)
    if show_b: cb = lb(e)
    doRu = lambda c, o, pp: plot3d(u,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    doRb = lambda c, o, pp: plot3d(b,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    R = doRu("blue", 0.2, pp) + doRb("yellow", 0.2, pp)
    if show_u:
        Cu = doRu("red", 1, ppc).add_condition(cu)
        R += Cu
    if show_b: 
        Cb = doRb("red", 1, ppc).add_condition(cb)
        R += Cb
    return R

A test run gives :

sage: %time doit(e=0.03, pp=200, ppc=200).show(frame=False, axes=True)
Launched html viewer for Graphics3d Object
CPU times: user 554 ms, sys: 32 ms, total: 586 ms
Wall time: 626 ms

Using Cython might get you yet another speedup factor, mating building an interact a viable proposition...

Implicitly : try someting along the lines of :

plot3d(U, (0, 2), (0, 2), color="blue", opacity=0.5) +\
plot3d(B, (0, 2), (0, 2), color="yellow", opacity=0.5) +\
plot3d(U, (0, 2), (0, 2), color="red", plot_points=100).add_condition(lambda t, u, v:abs(v-B(t, u))<0.02)

Labeling and other seasonings left to the reader...

An explicit solution is necessarily numeric...

EDIT :

Using Python functions rather than callable symbolic expression is way faster. After running :

# Python version
x, y, z = var("x, y, z")
# U(x,y) = x^(1/2)*y^(1/2)
# B(x,y) = (1/16)*x + y
def U(a, b): return sqrt(a)+sqrt(b)
def B(a, b): return a/16+b
def lu(e): return lambda a, b, c: abs(c-B(a, b))<=e
def lb(e): return lambda a, b, c: abs(c-U(a, b))<=e
def doit(e = 0.01, show_u = True,show_b = True, pp = 40, ppc = 100):
    if show_u: cu = lu(e)
    if show_b: cb = lb(e)
    doRu = lambda c, o, pp: plot3d(u,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    doRb = lambda c, o, pp: plot3d(b,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    R = doRu("blue", 0.2, pp) + doRb("yellow", 0.2, pp)
    if show_u:
        Cu = doRu("red", 1, ppc).add_condition(cu)
        R += Cu
    if show_b: 
        Cb = doRb("red", 1, ppc).add_condition(cb)
        R += Cb
    return R

A test run gives :

sage: %time doit(e=0.03, pp=200, ppc=200).show(frame=False, axes=True)
Launched html viewer for Graphics3d Object
CPU times: user 554 ms, sys: 32 ms, total: 586 ms
Wall time: 626 ms

Using Cython might get you yet another speedup factor, mating making building an interact a viable proposition...

Implicitly : try someting along the lines of :

plot3d(U, (0, 2), (0, 2), color="blue", opacity=0.5) +\
plot3d(B, (0, 2), (0, 2), color="yellow", opacity=0.5) +\
plot3d(U, (0, 2), (0, 2), color="red", plot_points=100).add_condition(lambda t, u, v:abs(v-B(t, u))<0.02)

Labeling and other seasonings left to the reader...

An explicit solution is necessarily numeric...

EDIT :

Using Python functions rather than Sage's "symbolic functions" (a. k. a. callable symbolic expression expressions) is way faster. After running :

# Python version
x, y, z = var("x, y, z")
# U(x,y) = x^(1/2)*y^(1/2)
# B(x,y) = (1/16)*x + y
def U(a, b): return sqrt(a)+sqrt(b)
def B(a, b): return a/16+b
def lu(e): return lambda a, b, c: abs(c-B(a, b))<=e
def lb(e): return lambda a, b, c: abs(c-U(a, b))<=e
def doit(e = 0.01, show_u = True,show_b = True, pp = 40, ppc = 100):
    if show_u: cu = lu(e)
    if show_b: cb = lb(e)
    doRu = lambda c, o, pp: plot3d(u,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    doRb = lambda c, o, pp: plot3d(b,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    R = doRu("blue", 0.2, pp) + doRb("yellow", 0.2, pp)
    if show_u:
        Cu = doRu("red", 1, ppc).add_condition(cu)
        R += Cu
    if show_b: 
        Cb = doRb("red", 1, ppc).add_condition(cb)
        R += Cb
    return R

A test run gives :

sage: %time doit(e=0.03, pp=200, ppc=200).show(frame=False, axes=True)
Launched html viewer for Graphics3d Object
CPU times: user 554 ms, sys: 32 ms, total: 586 ms
Wall time: 626 ms

image description

Using Cython might get you yet another speedup factor, making building an interact a viable proposition...

EDIT : Don't bother with what follows ; @achrzesz's answer to @Cyrille question is better ! I'm leaving this in place for the edification of future ask.sagemath.org (per-)users about the risks of obstination in the wrong direction.

Implicitly : try someting along the lines of :

plot3d(U, (0, 2), (0, 2), color="blue", opacity=0.5) +\
plot3d(B, (0, 2), (0, 2), color="yellow", opacity=0.5) +\
plot3d(U, (0, 2), (0, 2), color="red", plot_points=100).add_condition(lambda t, u, v:abs(v-B(t, u))<0.02)

Labeling and other seasonings left to the reader...

An explicit solution is necessarily numeric...

EDIT :

Using Python functions rather than Sage's "symbolic functions" (a. k. a. callable symbolic expressions) is way faster. After running :

# Python version
x, y, z = var("x, y, z")
# U(x,y) = x^(1/2)*y^(1/2)
# B(x,y) = (1/16)*x + y
def U(a, b): return sqrt(a)+sqrt(b)
def B(a, b): return a/16+b
def lu(e): return lambda a, b, c: abs(c-B(a, b))<=e
def lb(e): return lambda a, b, c: abs(c-U(a, b))<=e
def doit(e = 0.01, show_u = True,show_b = True, pp = 40, ppc = 100):
    if show_u: cu = lu(e)
    if show_b: cb = lb(e)
    doRu = lambda c, o, pp: plot3d(u,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    doRb = lambda c, o, pp: plot3d(b,(0, 2), (0, 2), color=c, opacity=o, plot_points=pp)
    R = doRu("blue", 0.2, pp) + doRb("yellow", 0.2, pp)
    if show_u:
        Cu = doRu("red", 1, ppc).add_condition(cu)
        R += Cu
    if show_b: 
        Cb = doRb("red", 1, ppc).add_condition(cb)
        R += Cb
    return R

A test run gives :

sage: %time doit(e=0.03, pp=200, ppc=200).show(frame=False, axes=True)
Launched html viewer for Graphics3d Object
CPU times: user 554 ms, sys: 32 ms, total: 586 ms
Wall time: 626 ms

image description

Using Cython might get you yet another speedup factor, making building an interact a viable proposition...