Possible bug in solve()

12 views
Skip to first unread message

dean moore

unread,
Mar 18, 2008, 11:14:52 PM3/18/08
to sage-s...@googlegroups.com
I was fiddling, trying to hack a solution to my recent max / min value hassles, and
was playing with solve(), discussed here.

I wondered if this was a strict polynomial thing, but, snippets:

f = x*sin(x^2)
solve(f(x) == 0)


gave

[x == 0]

and,

f = cos(x^2 -1)
solve(f(x) == 0)


gave two nice answers,        

[x == -sqrt(pi + 2)/sqrt(2), x == sqrt(pi + 2)/sqrt(2)]


but returning to the first example & dividing by x cubed:

f = x*sin(x^2)/x^3
solve(f(x) == 0)


gave

[x == 0]


and

f = x*sin(x^2)/x^4
solve(f(x) == 0)


whose functiuon can't be "limited" to make sense at x = 0, gave

[x == 0]


Again, how functions are defined seems important,

def f(x)
  return cos(x)
solve(f, x)


gave

Syntax Error:
    def f(x)

These are from online notebook, but both gave same results in Ubuntu.

Any ideas appreciated.  Still searching for a way to find min/max of a "nice" function on a closed
interval.

Dean

Carl Witty

unread,
Mar 20, 2008, 12:17:51 PM3/20/08
to sage-support
On Mar 18, 8:14 pm, "dean moore" <deanlorenmo...@gmail.com> wrote:
> I was fiddling, trying to hack a solution to my recent max / min value
> hassles, and
> was playing with solve(), discussed
> here<http://www.sagemath.org/doc/html/ref/module-sage.calculus.equations.html>.
>
> I wondered if this was a strict polynomial thing, but, snippets:
> *
> f = x*sin(x^2)
> solve(f(x) == 0)*
>
> gave
>
> *[x == 0]
> *
> and,
> *
> f = cos(x^2 -1)
> solve(f(x) == 0)*
>
> gave two nice answers,
> *
> [x == -sqrt(pi + 2)/sqrt(2), x == sqrt(pi + 2)/sqrt(2)]*
>
> but returning to the first example & dividing by *x* cubed:
> *
> f = x*sin(x^2)/x^3
> solve(f(x) == 0)*
>
> gave*
>
> [x == 0]*
>
> and*
>
> f = x*sin(x^2)/x^4
> solve(f(x) == 0)*
>
> whose functiuon can't be "limited" to make sense at x = 0, gave
> *
> [x == 0]*

The above look like bugs to me, but they may be difficult to fix.

> Again, how functions are defined seems important,
> *
> def f(x)
> return cos(x)
> solve(f, x)*
>
> gave*
>
> Syntax Error:
> def f(x)
> *

This is because you're missing the colon at the end of the line "def
f(x)". If you add the colon to correctly define the function, you can
then get

sage: solve(f(x) == 0)
[x == pi/2]

But yes, it does matter how the function is defined. With "def", you
get a Python function that takes a symbolic expression and returns a
symbolic expression; the other examples above gave symbolic
functions.

Carl

Carl Witty

unread,
Mar 20, 2008, 4:23:04 PM3/20/08
to sage-support
On Mar 18, 8:14 pm, "dean moore" <deanlorenmo...@gmail.com> wrote:
> f = x*sin(x^2)/x^4
> solve(f(x) == 0)*
>
> whose functiuon can't be "limited" to make sense at x = 0, gave
> *
> [x == 0]*

I've reported this as a bug here: http://trac.sagemath.org/sage_trac/ticket/2617

> Any ideas appreciated. Still searching for a way to find min/max of a
> "nice" function on a closed
> interval.

find_minimum_on_interval() "should" work; presumably at some point
http://trac.sagemath.org/sage_trac/ticket/2607 will be fixed and it
will work.

Until then, you could try calling scipy.optimize.anneal or
scipy.optimize.brute directly.

Carl
Reply all
Reply to author
Forward
0 new messages