parametric plot

64 views
Skip to first unread message

Gema María Diaz

unread,
Jul 4, 2022, 7:56:26 AM7/4/22
to sage-devel
Hello,

I've the following curve,

t=var('t')
C=[(-exp(2*t) + (-t^2 - 2*t)*ln(t)^2 - t^6 + 2*exp(t)*t^3)/(exp(2*t) + (t^2 - t)*ln(t)^2 + t^6 - 2*exp(t)*t^3), ((28*t^18 + 60*ln(t)^2*t^14 + 36*ln(t)^4*t^10 - 10*ln(t)^3*t^10 + 4*t^6*ln(t)^6 - 6*ln(t)^5*t^6)*exp(2*t) + (-56*t^15 - 80*ln(t)^2*t^11 - 24*ln(t)^4*t^7 + 10*ln(t)^3*t^7 + 2*ln(t)^5*t^3)*exp(3*t) + (70*t^12 + 60*ln(t)^2*t^8 + 6*ln(t)^4*t^4 - 5*ln(t)^3*t^4)*exp(4*t) + (-56*t^9 - 24*ln(t)^2*t^5 + ln(t)^3*t)*exp(5*t) + (28*t^6 + 4*t^2*ln(t)^2)*exp(6*t) - 8*exp(7*t)*t^3 + exp(8*t) + (t^8 + t^4)*ln(t)^8 + ((t^5 + 2*t^3)*exp(t) - t^8 - 2*t^6)*ln(t)^7 + (4*t^12 - 8*t^9*exp(t))*ln(t)^6 + (-2*t^12 + 6*t^9*exp(t))*ln(t)^5 + (6*t^16 - 24*t^13*exp(t))*ln(t)^4 + (-t^16 + 5*t^13*exp(t))*ln(t)^3 + (4*t^20 - 24*t^17*exp(t))*ln(t)^2 + t^24 - 8*exp(t)*t^21)/(2*(((3*t^4 - 2*t^3)*ln(t)^4 + (18*t^8 - 6*t^7)*ln(t)^2 + 15*t^12)*exp(2*t) + ((-12*t^5 + 4*t^4)*ln(t)^2 - 20*t^9)*exp(3*t) + ((3*t^2 - t)*ln(t)^2 + 15*t^6)*exp(4*t) - 6*exp(5*t)*t^3 + exp(6*t) + (t^6 - t^5)*ln(t)^6 + (t^5/2 - exp(t)*t^2/2)*ln(t)^5 + ((-6*t^7 + 4*t^6)*exp(t) + 3*t^10 - 2*t^9)*ln(t)^4 + ((-12*t^11 + 4*t^10)*exp(t) + 3*t^14 - t^13)*ln(t)^2 + t^18 - 6*exp(t)*t^15)*(exp(2*t) + t^2*ln(t)^2 + t^3*(t^3 - 2*exp(t))))]

and I'd like to see how it is like. Just with:

parametric_plot(C, (t,0,80), plot_points=5500)

one sees what's going on. However, with 

parametric_plot(C, (t,0,90), plot_points=5500)

suddenly a vertical lines  appears. I think it is a bug, am I right ?

thanks
Gema M.

G. M.-S.

unread,
Jul 4, 2022, 10:15:02 AM7/4/22
to sage-...@googlegroups.com

Hi Gema.

Doing

sage: xt,yt=C[0],C[1]

sage: xt.taylor(t,oo,3)

-6*t^4*e^(-3*t)*log(t)^2 - 3*t*e^(-2*t)*log(t)^2 - 1

sage: yt.taylor(t,oo,3)

1/2*t*e^(-2*t)*log(t)^2 + 1/2*(2*t^4*log(t)^2 + t*log(t)^3)*e^(-3*t) + 1/2

sage: 


you see that it converges towards (-1, 1/2) exponentially quickly.

HTH,

Guillermo

G. M.-S.

unread,
Jul 4, 2022, 10:21:58 AM7/4/22
to sage-...@googlegroups.com

Sorry, my message was incomplete.

So yes, there is a problem.

Niranjana K M

unread,
Jul 4, 2022, 11:12:58 AM7/4/22
to sage-devel
Some thing happened after t=89. Is it because of the following two cases:


for T in srange(1,100,1.0):
    print(T, float(C(T)[0]), float(C(T)[1]))
.....
87.0000000000000 -0.9999999999999999   0.5000000000000001
88.0000000000000 -0.9999999999999999   0.5
89.0000000000000 -1.0                  0.5
90.0000000000000 -1.0                  0.5
91.0000000000000 -1.0                  0.5
92.0000000000000 -0.9999999999999999   0.5
93.0000000000000 -1.0                  0.5
94.0000000000000 -1.0                  0.5
95.0000000000000 -1.0                  0.49999999999999994
96.0000000000000 -1.0                  0.5000000000000001
97.0000000000000 -1.0                  0.5
98.0000000000000 -0.9999999999999999   0.49999999999999994
99.0000000000000 -1.0                  0.49999999999999994



for T in srange(1,100,1):
    print(T, float(C(T)[0]), float(C(T)[1]))
.....
87   -0.9999999999999999   0.5
88   -0.9999999999999999   0.49999999999999994
89   -1.0                  inf
90   -1.0                  inf
91   -1.0                  inf
92   -0.9999999999999999   inf
93   -1.0                  inf
94   -1.0                  nan
95   -1.0                  nan
96   -1.0                  nan
97   -1.0                  nan
98   -0.9999999999999999   nan
99   -1.0                  nan

Niranjana K M

unread,
Jul 4, 2022, 11:25:05 AM7/4/22
to sage-devel
Also the following:

> parametric_plot(C, (t,89.0,95.0))
.....
verbose 0 (2200: graphics.py, get_minmax_data) ymin was NaN (setting to 0)
verbose 0 (2200: graphics.py, get_minmax_data) ymax was NaN (setting to 0)

> parametric_plot(C, (t,89,95))
.....
verbose 0 (2200: graphics.py, get_minmax_data) ymin was NaN (setting to 0)
verbose 0 (2200: graphics.py, get_minmax_data) ymax was NaN (setting to 0)


Regards
Niranjana

Samuel Lelievre

unread,
Jul 4, 2022, 11:27:18 AM7/4/22
to sage-devel
The expressions for the coordinates involve exp(8*t) and t^24.

sage: exp(8*88.)
5.53751938928459e305

sage: 88.^24
4.65140474534598e46

G. M.-S.

unread,
Jul 4, 2022, 4:13:59 PM7/4/22
to sage-...@googlegroups.com

I agree with Samuel that the numbers involved are huge.
After

sage: xtn,xtd=xt.numerator_denominator()

sage: ytn,ytd=yt.numerator_denominator()


one can see that

xtn ~ - e^(2*t)

xtd ~ e^(2*t)

ytn ~ e^(8*t)

ytd ~ 2*e^(8*t)


However, SageMath has no problems evaluating it:

sage: for i in sxrange(10000.,10010.,1):

....:     print(xt(t=i),yt(t=i))

....: 

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

-1.00000000000000 0.500000000000000

sage: 

Samuel Lelievre

unread,
Jul 6, 2022, 3:14:30 PM7/6/22
to sage-devel
In case the hope in extending the range of t further and further
was to capture the missing portion of the curve, it turns out
the problem is at the other end, near zero.

The curve is missing its initial segment, because

- parametric_plot(C, (t, a, b)) uses equispaced evaluation points
  along the interval [a, b], skipping points where evaluation fails
- C cannot be evaluated at zero
- C travels quite some distance when t runs through (0, 0.01)

To better view the curve, plot an initial arc separately,
say for t in the interval (10^-9, 10^-2); then the rest of
the curve, say up to t = 7.
```
pa = parametric_plot(C, (t, 1e-9, 1e-2), color='steelblue')
pb = parametric_plot(C, (t, 1e-2, 7), color='steelblue')
p = pa + pb
p.show()
```

There is not much point plotting further than t = 7.
Check how short the arc for t running along [7, 88] is:
```
pc = parametric_plot(C, (t, 7, 88), color='firebrick')
pc.show(xmin=-1.001, xmax=-0.999, ymin=0.495, ymax=0.505, aspect_ratio=1/10)
```

Niranjana K M

unread,
Jul 7, 2022, 5:09:08 AM7/7/22
to sage-...@googlegroups.com
Apart from just looking at this particular plot and trying to manage it, look at the actual problem in depth. Please look at how plotting points are evaluated. Even though Sage is capable of evaluating these points, it (or matplotlib?) is evaluating y coordinates after 88 as inf or nan.

Please see my post above with one evaluation with
    for T in srange(1,100,1.0):
and another with
        for T in srange(1,100,1):
The difference is that the increment is a float. And also range(1,100,1) produces the same result as srange(1,100,1).

Also,
    > parametric_plot(C, (t,89.0,95.0))
clearly says that here the y values above 88 are evaluated as inf or nan even though they are not and Sage is capable of evaluating them correctly.

    What if these things creep into plotting ranges which we are really interested in, where we expect y value to be a finite value but the program calculates as inf or nan.

    Here one thing to observe is that the vertical line is appearing because after 88 the y value is wrongly calculated as inf or nan and the plotter is turning them into 0 to handle it and hence the plot suddenly falls to y=0 (x is not affected though).

Regards
Niranjana


--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/5GkgeGQjr7A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/dd9fa495-fd3e-44d4-83ba-1f77ed235144n%40googlegroups.com.

Gema María Diaz

unread,
Aug 2, 2022, 10:21:49 AM8/2/22
to sage-...@googlegroups.com
Thanks a lote for your useful comments.

GM. 

You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAMcUJ1t%3Dym%3D5YqKaGA6JF2dY2Kgs_PTD8mggLDyCsz%3D_UwAsHQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages