# Plotting question: use higher precision when evaluating the function?

31 views

### John H Palmieri

Aug 31, 2018, 2:15:21 PM8/31/18
to sage-support
The question

brought the following question to mind: can you specify the precision to which a function is evaluated when plotting it? The particular ask.sagemath.org question involves a function which has "inherent numerical instability", as kcrisman says in his answer. For example, evaluating V(20, 1).n() will result in "ValueError: power::eval(): division by zero", but V(20,1).n(300) gives an actual number. Is there a way to pass the numerical precision to the plot function?

(I am not an expert in the plotting code in Sage, but when I look at the plot code, I see the function "generate_plot_points" which calls float(f(...)). That makes me think that the available precision is fixed. But maybe I'm wrong.)

--
John

### William Stein

Aug 31, 2018, 2:44:37 PM8/31/18
to sage-support
I wrote a lot of the plot code and I think it only works with floats.
I don't think we implemented anything at all to automatically deal
with high precision.

As a workaround, if you have a function f you want to plot to high
precision, maybe do this:

R = RealField(500)
def wrap(x):
# x is a floating point number
return f(R(x))

plot(wrap, ...)

---

Alternatively, compute in any way you want (to very high precision) a
list v of pairs (x,y), then do "line(v)" to get a plot of that.

>
> --
> John
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

--
William (http://wstein.org)