ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 27 Jun 2014 05:55:47 -0500Fastest way to call special function (elliptic integral) from cython code for gsl ode_solver()http://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 05:55:47 -0500http://ask.sagemath.org/question/11058/Fermi-Dirac integral of half orderhttp://ask.sagemath.org/question/10517/fermi-dirac-integral-of-half-order/I am trying to implement a 1D model for semiconductor pn-junctions. This involves evaluating the Fermi-Dirac integral of half order, which can only be done numerically. I saw that the GSL library has an algorithm to perform this integration, but I can't figure out how to call it in Sage, is this possible? If not, what are some alternatives to evaluate this integral? Thanks in advance.wlp2Fri, 06 Sep 2013 07:20:20 -0500http://ask.sagemath.org/question/10517/Plotting Bessel functionhttp://ask.sagemath.org/question/9370/plotting-bessel-function/ plot(Bessel(0,'J'),0,10)
gives me a plot of the Bessel function. However:
plot(Bessel(0,'J'),0,10,color='red')
gives me an error:
TypeError: plot() got an unexpected keyword argument 'rgbcolor'
even though:
plot(sin,0,10,color='red')
works.
I am using the developmental version of sage. Any help to resolve this is appreciated.
R CSun, 30 Sep 2012 04:07:31 -0500http://ask.sagemath.org/question/9370/How can one use maxima kummer confluent functions in sagehttp://ask.sagemath.org/question/8727/how-can-one-use-maxima-kummer-confluent-functions-in-sage/Hi, here is my piece of code
var('x,m')
assume(m, 'integer')
y = function('y', x)
desolve(diff(y,x,2) + 2*x*diff(y,x) - 4*m*y, y,contrib_ode=true,ivar=x)
which yields
[y(x) == k1*kummer_m(-m, 1/2, -x^2) + k2*kummer_u(-m, 1/2, -x^2)]
Internet(Wikipedia) sais that the solutions to this differential equation are the Kummer functions or Confluent_hypergeometric_functions. I now want to know how I can use these functions in sage since they must be defined in maxima.
Thanks in advancegod.oneMon, 20 Feb 2012 22:20:27 -0600http://ask.sagemath.org/question/8727/