On Feb 8, 4:30 pm, "
DweeberlyL...@gmail.com" <
DweeberlyL...@gmail.com>
wrote:
> Ok, I'm getting a little closer ... here is the program (it was easier
> once I realized the syntax was python):
>
> maxie = 1000
> def sinie(x):
> rv=0.0
> for n in range(1,maxie):
> rv += sin(x^n)
> return rv
> p = plot(sinie, 0.0, pi/2)
> show(p)
>
> This works until I increase the plot range to pi, where it gives me
> the following error:
> File "/home/notebook/sage_notebook/worksheets/admin/4/code/38.py",
> line 8, in sinie
> rv += sin(x**n)
> OverflowError: (34, 'Numerical result out of range')
>
> I believe this is because I am exceeding the range of a double, but
> I'm still not sure how to change the numeric precision so that this
> will not happen :-(
>
> Suggestions?
Here is some code that will plot samples from this curve:
maxie = 1000
RF = RealField(maxie*3 + 20)
def sinie(x):
rfx = RF(x)
rfxn = RF(1)
rv=float(0.0)
for i in (1..maxie):
rfxn = rfxn*rfx
rv = rv + sin(rfxn)
return rv
plot(sinie, 0, 2*pi)
With this code, sinie will give reasonably accurate results on the
arguments you pass it. I've tried this with maxie=3, 20, and 100, and
got plausible-looking plots. Doing a plot with maxie=1000 is quite
slow, and my plot has not terminated yet.
Let me emphasize again that THE REAL FUNCTION LOOKS NOTHING LIKE THE
PLOTS YOU WILL GET WITH THIS METHOD. For x>1.2 or so, you might as
well just plot random numbers.
You can make things faster, at the cost of having sinie return
incorrect values, by changing the "RF =" line to "RF =
RealField(53)". But it doesn't really matter that sinie returns
incorrect values, since they might as well be random anyway...
Carl