Ask Your Question
0

A parametric plot with branches for which restricting the range with xmin, xmax doesn't work

asked 2021-12-04 20:12:17 +0200

florin gravatar image

updated 2021-12-05 10:17:07 +0200

Hi The following plot

var('t')
parametric_plot( (8*(6+t)/(t^2-16), 2*(8+ 3 *t)/(t^2-16)), (t, -6, 6),xmin=-3,xmax=3,detect_poles=True)

has three branches. 1) For some reason, the plot is not correct. Also

var('t')
parametric_plot( (8*(6+t)/(t^2-16), 2*(8+ 3 *t)/(t^2-16)), (t, -6, 6),xmin=-3,xmax=3,ymin=-3,ymax=3)

fails. 2)How to plot the branches in different colors? 3) Can I add a point moved by a cursor when t increases, like with the Mathematica command Manipulate? Or make an animation to show how a point traverses the three branches?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-12-05 10:33:32 +0200

Emmanuel Charpentier gravatar image

updated 2021-12-07 22:34:24 +0200

For some reason, the plot is not correct.

You mean that xmin and xmax are not honored ? See Trac#16686 and the ticket-chain referenced...

Workaround :

sage: def ininterval(x,l,u):return float(x) if x>l and x<u else float("NaN")
sage: plot([lambda t:ininterval(8*(6+t)/(t^2-16),-3,3),lambda t:ininterval(2*(8+ 3 *t)/(t^2-16),-3,3)], (t,-6,6), axes_labels=["x","y"], parametric=True)
verbose 0 (3839: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 130 points.
verbose 0 (3839: plot.py, generate_plot_points) Last error message: 'Unable to compute f(6.0)'
Launched png viewer for Graphics object consisting of 2 graphics primitives

image description

has three branches.

Nope.

What are the possible values of x and y for $t\in[-6~6]$ ? An analytical solution is possible by solving x and y for t then solving the inequations for $t\in|-5~6]$, but is somewhat painful... A graphical solution is easier to grasp :

sage: plot([lambda t:ininterval(8*(6+t)/(t^2-16),-30,30),lambda t:ininterval(2*(8+ 3 *t)/(t^2-16),-30,30)], (t,-6,6), axes_labels=["t",""], legend_label=["x","y"])+plot([-3, 3],(-6,6),color=["green","red"])
verbose 0 (3839: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 14 points.
verbose 0 (3839: plot.py, generate_plot_points) Last error message: 'Unable to compute f(4.325615967306306)'
Launched png viewer for Graphics object consisting of 8 graphics primitives

image description

The most limiting variable is x, which is positive and <3 for t>-6, t> -9/2 approximately, and slightly superior to -3 for t>-3, t<0 approximately.

How to plot the branches in different colors ?

The painful analytical solution I studiously avoided above is necessary to define the different regions; the color= argument can then be built around this definition (left tothe reader as an exercise;-)...

EDIT : after addition of another question...

A static version of your chronogram could be :

var("t")
fx(t)=8*(6+t)/(t^2-16)
fy(t)=2*(8+ 3 *t)/(t^2-16)
def ininterval(x,l,u):return float(x) if x>l and x<u else float("NaN")
P=plot([lambda t:ininterval(fx(t),-3,3), lambda t:ininterval(fy(t),-3,3)],
       (t,-6,6), axes_labels=["x","y"], parametric=True)
Pts=[]
T=[]
xmin=P.xmin()
xmax=P.xmax()
ymin=P.ymin()
ymax=P.ymax()
for t in srange(-6,6.1,0.1):
    px=fx(t)
    py=fy(t)
    if px>=xmin and px<=xmax and py>=xmin and py<=ymax:
        Pts+=[(px,py)]
        T+=[text("%4.1f"%t,(px,py),
                 vertical_alignment="bottom",
                 horizontal_alignment="left",
                 color="black")]
sage: show(P+points(Pts)+sum(T))
Launched png viewer for Graphics object consisting of 43 graphics primitives

image description

An animated/interactive version is left to the reader of the documentation as an exercise...

HTH,

edit flag offensive delete link more

Comments

Thanks for the fixup of parametricplot ! indeed the three branches appear only after enlarging the t range to say -8,8, and indeed, before doing animations, I should start with static version :)
One more question : why doesn't just composing ``ininterval(fx(t),-3,3)" , without lambda t: , work? I know what lambda does, but is there also a way to use the syntax of the composition of functions?

florin gravatar imageflorin ( 2021-12-08 07:40:47 +0200 )edit

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: 2021-12-04 20:12:17 +0200

Seen: 164 times

Last updated: Dec 07 '21