On 2015-03-10, M M <mirettemarz...@gmail.com> wrote:
> I get different results from Sage when I try to get a numerical 
> approximation for an expression and if I use evaluate a preparse of the 
> string. I get different results on different versions of sage as well. Here 
> are samples:

Integration is done by Maxima, and it is a bloody mess; e.g.
(with Sage 6.6.beta3)

sage: numerical_integral(x/(x^3-x+1.), 1., 2.)   
(0.565799916456428, 6.281640945809164e-15)
sage: integral(x/(x^3-x+1), x, 1, 2).n()         
1.11396858782562
sage: integral(x/(x^3-x+1), x, 1, 2).full_simplify().n()
0.168522351678247
sage: 

Do you know which one is actually correct? 
It looks like the 2nd one might be right (by looking at
sage: plot(x/(x^3-x+1), x, 1, 2))


PS. .n() is the same as numerical_approx()


>
> ----------------------------------------------------------------------
>
>| Sage Version 5.3, Release Date: 2012-09-08                         |
>
>| Type "notebook()" for the browser-based notebook interface.        |
>
>| Type "help()" for help.                                            |
>
> ----------------------------------------------------------------------
>
> sage: eval(preparse("numerical_approx(integral(x/(x^3-x+1), x, 1, 2))"))
>
> 0.132008722884722
>
> sage: numerical_approx(integral(x/(x^3-x+1), x, 1, 2))
>
> 0.132008722884722
>
> sage: A = integral(x/(x^3-x+1), x, 1, 2)
>
> sage: A_str = str(A)
>
> sage: eval(preparse("numerical_approx("+A_str +")"))
>
> -0.393296585552547
>
> sage: 
>
>
> ┌────────────────────────────────────────────────────────────────────┐
> │ Sage Version 6.5, Release Date: 2015-02-17                         │
> │ Type "notebook()" for the browser-based notebook interface.        │
> │ Type "help()" for help.                                            │
> └────────────────────────────────────────────────────────────────────┘
> sage: eval(preparse("numerical_approx(integral(x/(x^3-x+1), x, 1, 2))"))
> 1.45943044687563
> sage: numerical_approx(integral(x/(x^3-x+1), x, 1, 2))
> 1.45943044687563
> sage: A = integral(x/(x^3-x+1), x, 1, 2)
> sage:
> sage: A_str = str(A)
> sage:
> sage: eval(preparse("numerical_approx("+A_str +")"))
> 0.159046901967485
> sage:
>
> ┌────────────────────────────────────────────────────────────────────┐
> │ Sage Version 6.2, Release Date: 2014-05-06                         │
> │ Type "notebook()" for the browser-based notebook interface.        │
> │ Type "help()" for help.                                            │
> └────────────────────────────────────────────────────────────────────┘
> sage: eval(preparse("numerical_approx(integral(x/(x^3-x+1), x, 1, 2))"))
> 1.64714767119638
> sage: numerical_approx(integral(x/(x^3-x+1), x, 1, 2))
> 1.64714767119638
> sage: A = integral(x/(x^3-x+1), x, 1, 2)
> sage: A_str = str(A)
> sage: eval(preparse("numerical_approx("+A_str +")"))
> 0.162416510011260
> sage:
>
>
> On the Notebook on the cloud it gives me the following error although the 
> version is the same as one of the versions I tried locally
> version()
> 'Sage Version 6.5, Release Date: 2015-02-17'
>
> numerical_approx(integral(x/(x^3-x+1), x, 1, 2))
> Error in lines 1-1 Traceback (most recent call last): File 
> "/projects/f700a2f3-7f30-4b47-9f18-e0309eb8c48c/.sagemathcloud/sage_server.py",
>  
> line 875, in execute exec compile(block+'\n', '', 'single') in namespace, 
> locals File "", line 1, in <module> File "<string>", line 1, in <module> 
> File 
> "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/misc/functional.py",
>  
> line 1298, in numerical_approx return x._numerical_approx(prec, 
> algorithm=algorithm) File "sage/symbolic/expression.pyx", line 4861, in 
> sage.symbolic.expression.Expression._numerical_approx 
> (build/cythonized/sage/symbolic/expression.cpp:27184) x = 
> self._convert(kwds) File "sage/symbolic/expression.pyx", line 1034, in 
> sage.symbolic.expression.Expression._convert 
> (build/cythonized/sage/symbolic/expression.cpp:7790) cdef GEx res = 
> self._gobj.evalf(0, kwds) ValueError: power::eval(): division by zero
>
>

-- 
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 email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to