ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Apr 2019 00:56:34 +0200Elliptic Integral Bug?https://ask.sagemath.org/question/46072/elliptic-integral-bug/ Hi,
How did Sage come up with a nice answer when being asked to compute the following elliptic integral of the second kind?
$$\int \sqrt{1-(1/2)\sin^2(x)}dx$$
Using *integral(f(x),x)*, SageMathCell returns:
$$-\frac{\sqrt{2}}{48}(\sin(3x)-\sin(x))$$
Here is [the link](https://sagecell.sagemath.org/?z=eJxL06jQtC0uLCrRMNTVMNQ30tQqzswDisUZaXIVZ-SXa6QBOZpcXJ62mXklqelFiTlgEZ0KqLSnJgCBUBNa&lang=sage&interacts=eJyLjgUAARUAuQ==).
Is it my maths, or is it bug?
Thanks,
Julien
JulienWed, 10 Apr 2019 00:56:34 +0200https://ask.sagemath.org/question/46072/integral(rho*sqrt(1/(-m*sin(u)^2 + 1)),(u,0,x)) gives a wrong answerhttps://ask.sagemath.org/question/40771/integralrhosqrt1-msinu2-1u0x-gives-a-wrong-answer/HI everybody,
var('x u m')
assume(x>0)
assume(m>0)
assume(m<1)
integral(rho*sqrt(1/(-m*sin(u)^2 +1)),(u,0,x))
returns
2*rho*x/m
Expected answer is
elliptic_f(x,m)
Does anyone know how to fix this ?
Thank you.epimetheusThu, 25 Jan 2018 22:16:50 +0100https://ask.sagemath.org/question/40771/Unable to Simplify to Float Approximation for a Numerical Integralhttps://ask.sagemath.org/question/27225/unable-to-simplify-to-float-approximation-for-a-numerical-integral/Hello,
I'm trying to approximate a curve, here is my code:
a = 1 # x radius length
b = 1 # y radius length
cut = pi/4 # angle of plane
theta = var('theta')
phi = var('phi')
diffx = diff(a*cos(theta), theta)
diffy = diff(b*sin(theta), theta)
func = (diffx^2+diffy^2)^(1/2)
def getnumerical(i):
approx = numerical_integral(func, 0, i)
return approx[0]
parametric_plot((getnumerical(phi), b*sin(phi)*tan(cut)), (phi, 2*pi, 4*pi), aspect_ratio = 1)
The integral defining the x term in the parametric plot is elliptic, so it must be numerically approximated. So far, I have had little success getting any numerical integral methods to work, including nintegral, and am frustrated because I cannot discern the problem. This implementation gives the error:
Traceback (most recent call last):
File "", line 1, in <module>
File "/tmp/tmpDAHxNF/___code___.py", line 17, in <module>
exec compile(u'parametric_plot((getnumerical(phi), b*sin(phi)*tan(cut)), (phi, _sage_const_2 *pi, _sage_const_4 *pi), aspect_ratio = _sage_const_1 )
File "", line 1, in <module>
File "/tmp/tmpDAHxNF/___code___.py", line 14, in getnumerical
approx = numerical_integral(func, _sage_const_0 , i)
File "sage/gsl/integration.pyx", line 332, in sage.gsl.integration.numerical_integral (build/cythonized/sage/gsl/integration.c:3159)
File "sage/symbolic/expression.pyx", line 1177, in sage.symbolic.expression.Expression.__float__ (build/cythonized/sage/symbolic/expression.cpp:8897)
TypeError: unable to simplify to float approximation
Thank you for any help you provide.
Edit: With the constants defined as they currently are, this should plot a sine wave.WulfstaMon, 29 Jun 2015 04:29:35 +0200https://ask.sagemath.org/question/27225/Fastest way to call special function (elliptic integral) from cython code for gsl ode_solver()https://ask.sagemath.org/question/11058/fastest-way-to-call-special-function-elliptic-integral-from-cython-code-for-gsl-ode_solver/I am using **sage.gsl.ode.ode_solver** to solve an ode, and overloading the **c_f()** function as detailed [here](http://www.sagemath.org/doc/reference/calculus/sage/gsl/ode.html).
The code is working using an approximate **c_f()** function. For the exact one, I need to use the complete elliptic integrals. These are special functions that are not part of the libc.math library. They seem to be available through a couple packages on sage. I found I could call them by using **sage.all.elliptic_ec(k)** and **sage.all.elliptic_kc(k)**
This is causing the code to slow down by a factor of about 10^3. I know those special functions are going to be expensive, but timing the elliptic_ec() function in a separate cell returns 0 for the time, so these functions aren't *that* slow.
I'm wondering if the problem is mostly just that I'm calling a python function from cython and losing the speed up because of that? Is there a better way to do that? [There are](http://https://www.gnu.org/software/gsl/manual/html_node/Legendre-Form-of-Complete-Elliptic-Integrals.html#Legendre-Form-of-Complete-Elliptic-Integrals) c libraries available with those functions - would it be better to import the files into my project, and call them from the cython code? (not sure how to do that...) Sage seems to have some gsl packages already - does it also have those special functions through gsl? Is there a different package with a faster form of those functions?
Disclaimer: I've played around with sage a bit in the past, but this is the first intensive numerical simulation I've attempted with it, so sage/python/cython are all relatively new to me. I'm more accustomed to Mathematica, Matlab/Octave and c++
Here are (I believe) the relevant bits of code:
%cython
from libc.math cimport pow
cimport sage.gsl.ode
import sage.gsl.ode
include 'gsl.pxi'
cdef class zeeman_acceleration(sage.gsl.ode.ode_system):
... other stuff ...
cdef double coilFieldR(self, double rp, double zp, double coilR): # T
cdef double B0, alpha, beta, Q, k
... some basic arithmetic ...
if rp > coilR/10e4 :
gamma = zp/rp
EC = sage.all.elliptic_ec(k)
EK = sage.all.elliptic_kc(k)
Br = B0*gamma/(self.pi*sqrt(Q))*(EC*(1+alpha**2+beta**2)/(Q-4*alpha)-EK)
return Br
return 0
... other stuff (including c_f() function that calls coilField...
argentum2fFri, 27 Jun 2014 12:55:47 +0200https://ask.sagemath.org/question/11058/Integrate with elliptic integral special function in resulthttps://ask.sagemath.org/question/10123/integrate-with-elliptic-integral-special-function-in-result/I'm trying to work with the following integral:
$$\int\sqrt{1-\frac14(\cosh x)^2}\mathrm dx$$
Feeding this to sage as `integrate(sqrt(1-1/4*cosh(x)^2),x)` leaves it pretty much as it stands. [Feeding the same to Wolfram Alpha](http://www.wolframalpha.com/input/?i=integrate%28sqrt%281-1%2F4*cosh%28x%29^2%29%2Cx%29), I get a solution which at least at first glance looks better:
$$\int\sqrt{1-\frac14(\cosh x)^2}\mathrm dx=-\frac12i\sqrt3E\left(ix\Big\vert-\frac13\right)$$
So I wonder:
* **Is there a way to obtain this kind of output using sage?** (This is my main question.)
* In particular, is there a way to manually indicate that a given integral can likely be expressed in terms of elliptic integral functions, and that these would be of interest?
* Are these [elliptic integral functions](http://en.wikipedia.org/wiki/Elliptic_integral) even available at all inside sage? If they are, under what name?
* Is there any benefit in using these special elliptic integral functions, as opposed to (a `numeric_integral` version of) the original integral, in terms of performance or accuracy when dealing with actual numeric data?MvGWed, 15 May 2013 03:43:21 +0200https://ask.sagemath.org/question/10123/