On Saturday 16 February 2008, Carl Witty wrote:
> On Feb 12, 2:07 am, bill purvis <[EMAIL PROTECTED]> wrote:
> > I wanted to make a plot of x^3+y^3=1729 (the well-known taxicab problem).
> > I'm sure there are better ways of acieving this but I opted for a naive
> > approach:
> >
> > {{{
> > def sng(x):
> > if x < 0:
> > return -1
> > return 1
> >
> > def f(x):
> > y3 = 1729 - x^3
> > return sgn(y3) * abs(y3)^(1/3)
> >
> > }}}
> >
> > {{{
> > c = parametric_plot((x,f(x)),-15,15)
> > c.show()
> >
> > }}}
> >
> > (I want to add other things to the plot).
> > However, when I run this in the notebook, the plot has a cusp at x=12+
> > and behaves as if the sgn(x) has been taken as +1. I tried evaluating
> > f(x) at 12 and 13 and the result changes sign as I'd expect.
>
> The problem is here:
> sage: sgn(1729-x^3)
> 1
> sage: 1729-x^3 < 0
> 1729 - x^3 < 0
> sage: bool(1729-x^3 < 0)
> False
>
> You're applying the Python function f to the symbolic variable x,
> which calls sgn(1729-x^3). Then sgn(x) checks whether 1729-x^3<0,
> which is taken to mean "Can you prove that 1729-x^3 is always less
> than 0"? Since the answer is no, sgn() returns 1.
>
That's pretty subtle. Now you've explained it, it makes perfect
sense, but I'm still too much of a newbie to have spotted it.
> The fix is easy: instead of passing the symbolic expression f(x) to
> parametric_plot, pass the function f.
> c = parametric_plot((x,f),-15,15)
> Or even easier, there's no reason for this to be a parametric plot:
> c = plot(f,-15,15)
>
That's true enough. Trust me to make life difficult.
> As to whether there's a bug here... I don't know how to decide if any
> of the above should count as a bug. (I use the symbolic part of Sage
> very seldom.) If there is a bug, it may be difficult to fix. The
> thing I can see to do would be to make bool(x<0) signal an error,
> instead of just returning False; but I don't know how much that would
> break.
>
Many thanks for sorting me out on this one.
Bill
--
+---------------------------------------+
| Bill Purvis, Amateur Mathematician |
| email: [EMAIL PROTECTED] |
| http://bil.members.beeb.net |
+---------------------------------------+
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---