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.Thu, 10 Jun 2021 13:16:52 +0200Lazy evaluation of symbolic integrationhttps://ask.sagemath.org/question/57529/lazy-evaluation-of-symbolic-integration/I am confused by the output for the following code
var('x,u,w')
F(x)=integral((min_symbolic(u,0)-1/2)*exp(x*u),u,-1,1)
G(x)=F(x)
H(w)=F(w)
print("F:",F)
print("G:",G)
print("H:",H)
The output I am getting is
F: x |--> 1/2*integrate((2*min(0, u) - 1)*e^(u*x), u, -1, 1)
G: x |--> 1/2*integrate((2*min(0, u) - 1)*e^(u*x), u, -1, 1)
H: w |--> 1/2*(3*w*e^(-w) + 2*e^(-w) - 1)/w^2 - 1/2*(w*e^w + 1)/w^2
The output for H is what I am actually after, but I am wondering why it is different from the output for F and G, whether this is the intended behaviour and what is the official way to influence the evaluation/non-evaluation of such a symbolic integral expression.
Also this behaviour must have changed at some point in the recent past, breaking some of my existing code as a result.ibykusThu, 10 Jun 2021 13:16:52 +0200https://ask.sagemath.org/question/57529/Tips for Symbolic Integration of Rational Functions?https://ask.sagemath.org/question/57028/tips-for-symbolic-integration-of-rational-functions/I am doing some work that requires me to do a lot of symbolic integration of rational functions over the interval [-1, 1]. These rational functions end up containing the integration variable, plus a few real symbolic parameters t1,...,tn. The issue is, as I add more parameters and things get more complicated, Sage's integrate function slows down a lot, and even occasionally seems to get completely stuck.
I am reasonably new to Sage, and my code is able to handle the simpler cases, so it might just be that these functions become too complicated to integrate as I add more parameters. But I'm wondering, are there any general things I could do that might make the integration a little easier/faster? For example, I tried calling .partial_fractions() on the integrand before passing it to the integrate function, but I didn't really notice much of an effect. If you can think of anything that might help speed up these computations, I would appreciate it.OgrelordSun, 09 May 2021 00:03:28 +0200https://ask.sagemath.org/question/57028/Multivariable numerical-symbolic integrationhttps://ask.sagemath.org/question/55689/multivariable-numerical-symbolic-integration/I need to find the symbolic expression of a multivariable integral. The real integrand contains 11 variables (I have to integrate "only" four of them) so example code is simplified here:
x, y, z = var('x','y','z')
integrand = sin(x)*cos(y)*z
result = integrand.integral(x, 0, pi).integral(z, 0, 1)
It works just fine generally but given the complexity of the integral no algorithm gives me a result and it returns just:
integrate(integrate(sin(x)*cos(y), x, 0, pi), z, 0, 1)
Is there a built in way to numerically evaluate an integral on some variables that returns symbolic result with the numerical integration found coefficients (or constants)? Namely, in this case:
cos(y)
EDIT1: I managed to get a very very simple example of the function I need:
def numsym_integral( f, variable, a, b, points = 1000):
dx = (b-a)/points
result = 0
for i in range(0,points):
result = result + f.substitute({variable:a + i*dx}) * dx
return result
It still doesn't work though in my specific case because of the complexity of the expression. I get the number of terms gets multiplied by "points" per integration, leading to something too big. Could something built in be more efficient?MateCheckSat, 13 Feb 2021 10:59:07 +0100https://ask.sagemath.org/question/55689/How do I understand the result of symbolic integralshttps://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/So now I know how to integrate, but when I type in
sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
why don't I get back `(exp(x)-1)/x +C `?
Philipp SchneiderWed, 18 Aug 2010 20:04:12 +0200https://ask.sagemath.org/question/7574/Possible inconsistency in symbolic limitshttps://ask.sagemath.org/question/55370/possible-inconsistency-in-symbolic-limits/I was trying to manipulate some symbolic expressions and got an unexpected error.
Here is a minimal example,
u=integrate(x**3/(exp(x)-1),(x,0,oo))
The expression is quite messy, but the result is known. When I try to use any simplification routine, like
u.simplify()
sage displays the error message
RuntimeError: ECL says: Error executing code in Maxima: limit: direction must be either 'plus' or 'minus'; found: _SAGE_VAR_minus
As far I understood, the expression is defining lateral limits by symbolic variables, while maxima handle such limits as strings. If it is the case there is an internal conflict here. Is it the case?cav_rtWed, 20 Jan 2021 02:58:40 +0100https://ask.sagemath.org/question/55370/Unable to parse Giac output errorhttps://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/Sagemath 8.9
Why does sagemath return this error here?
sage: var('x')
x
sage: integrate((1-2*x^(1/3))^(3/4)/x,x, algorithm="giac")
NotImplementedError Traceback (most recent call last)
<ipython-input-16-987ddabbc645> in <module>()
----> 1 integrate((Integer(1)-Integer(2)*x**(Integer(1)/Integer(3)))**(Integer(3)/Integer(4))/x,x, algorithm="giac")
/usr/lib/python2.7/site-packages/sage/misc/functional.pyc in integral(x, *args, **kwds)
751 """
752 if hasattr(x, 'integral'):
--> 753 return x.integral(*args, **kwds)
754 else:
755 from sage.symbolic.ring import SR
/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:64032)()
12360 R = ring.SR
12361 return R(integral(f, v, a, b, **kwds))
> 12362 return integral(self, *args, **kwds)
12363
12364 integrate = integral
/usr/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in integrate(expression, v, a, b, algorithm, hold)
910 if not integrator:
911 raise ValueError("Unknown algorithm: %s" % algorithm)
--> 912 return integrator(expression, v, a, b)
913 if a is None:
914 return indefinite_integral(expression, v, hold=hold)
/usr/lib/python2.7/site-packages/sage/symbolic/integration/external.pyc in giac_integrator(expression, v, a, b)
430 return expression.integrate(v, a, b, hold=True)
431 else:
--> 432 return result._sage_()
/usr/lib/python2.7/site-packages/sage/interfaces/giac.pyc in _sage_(self, locals)
1096
1097 except Exception:
-> 1098 raise NotImplementedError("Unable to parse Giac output: %s" % result)
1099 else:
1100 return [entry.sage() for entry in self]
NotImplementedError: Unable to parse Giac output: Evaluation time: 1.76
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
sage:
The error is similar to one in this bug report from 3 years ago [https://trac.sagemath.org/ticket/22997](https://trac.sagemath.org/ticket/22997) but that is for unresolved integral while here Giac is able to solve it.
Here is the same thing using giac directly on same computer
>giac
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 4
Help file /usr/share/giac/doc/en/aide_cas not found
Added 26 synonyms
Welcome to giac readline interface
(c) 2001,2018 B. Parisse & others
Homepage http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
See http://www.gnu.org for license details
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
0>> integrate((1-2*x^(1/3))^(3/4)/x,x)
Evaluation time: 1.66
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
// Time 1.66
1>>
Version
>giac --version
// Using locale /usr/share/locale/
// en_US.utf8
// /usr/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 4
// (c) 2001, 2018 B. Parisse & others
1.5.0
>
Any suggestions what is going on?
Thanks
--Nasser
NasserWed, 25 Dec 2019 06:19:43 +0100https://ask.sagemath.org/question/49176/How to do quantum mechanics integrals in Sage?https://ask.sagemath.org/question/54774/how-to-do-quantum-mechanics-integrals-in-sage/Hi.
I am a newcomer to Sage. I am trying to do integrals of the form shown below. This is from an introductory course in quantum mechanics.
$
\psi(x, t) = \int_{-\infty}^{+\infty} f(p) \psi_p(x - x_0, t) d\mathrm{p}
$
where,
$
\psi_p(x, t) = \dfrac{1}{\sqrt{2\pi\hbar}}e^\left( -\dfrac{i}{\hbar}\left(\dfrac{p^2}{2m}t - px \right)\right)
$
$
f(p) = \dfrac{1}{(2\pi)^{1/4} \sqrt{\sigma_p}}e^\left( -\dfrac{(p - p_0)^2}{4{\sigma_p}^2}\right)
$
I have tried the following in sage thus far:
forget()
var('x,t,p,p_0, m,h,x_0,sigma_p')
psi_p(x, t) = 1/(2*pi*h)^(1/2)*exp(-i/h*(p^2*t/(2*m) - p*(x - x_0)))
f(p) = 1/(2*pi)^(1/4)*1/sqrt(sigma_p)*exp(-(p - p_0)^2/(4*sigma_p^2))
show(psi_p(x, t))
show(f(p))
assume(m, 'constant')
assume(m > 0)
assume(h, 'constant')
assume(h > 0)
assume(p_0, 'constant')
assume(p_0 > 0)
assume(sigma_p, 'constant')
assume(sigma_p > 0)
assume(x, 'real')
assume(t, 'real')
from sage.symbolic.integration.integral import definite_integral
definite_integral(f(p)*psi_p(x, t), p, -oo, +oo)
Sage keeps complaining about requiring assumptions that I can't easily provide. Here is a sample output:
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(2*sigma_p^2*t
>0)', see `assume?` for more details)
Is 2*sigma_p^2*t
*sin(atan((2*sigma_p^2*t)/(h*m))
/2)
+h*m
*cos(atan((2*sigma_p^2*t)
/(h*m))
/2) positive, negative or zero?
My question: how would you do integrals like this in Sage? Is my fundamental approach correct?ARVSun, 20 Dec 2020 14:41:49 +0100https://ask.sagemath.org/question/54774/why sagemath can integrate a string?https://ask.sagemath.org/question/49165/why-sagemath-can-integrate-a-string/ I am surprised this works. Sagemath 8.9
sage: var('x')
x
sage: integrate("x",x)
1/2*x^2
sage: type("x")
<type 'str'>
Why does sagemath accept string for the integrand? Should not this be type error? Maple:
restart
int("x",x)
Error, (in int) wrong number (or type) of arguments: wrong type of integrand passed to indefinite integration.
NasserTue, 24 Dec 2019 14:46:54 +0100https://ask.sagemath.org/question/49165/Solved: Why does integrate(psi(y)*f(y),y) return an error but integrate(psi(t,y)*f(t,y),y) works?https://ask.sagemath.org/question/43287/solved-why-does-integratepsiyfyy-return-an-error-but-integratepsityftyy-works/Hi there,
I am trying get an symbolic expression for the convolution
$$ (\psi \star f)(x) := \int\limits_{\mathbb{R}} \psi(x-y) f(y) {d y} $$
of two functions
$
f, \psi: \mathbb{R} \to \mathbb{R}
$
as follows:
<code>
var('y') <br>
psi = function('psi')(y) <br>
f = function('f')(y) <br>
integrate(psi(x-y)*f(y),y)
</code>
upon which I get the error message
> RuntimeError: ECL says: Error executing code in Maxima:
If I add an extra argument to the two functions and define them as
$$ f, \psi : \mathbb{R} \times \mathbb{R} \to \mathbb{R} $$
as follows:
<code>
var('t') <br>
psi = function('psi')(t,y) <br>
f = function('f')(t,y) <br>
integrate(psi(t,x-y)*f(t,y),y)
</code>
there is a surprise, *it suddenly works!*
I get the desired symbolic expression on which I can run diff(..,x) and all the other built-in functions.
**TL;DR**
Why does <code>integrate(psi(y)*f(y),y)</code> return an error?
**Solution**
Use sympy backend for symbolic integration as in
<code>integrate(psi(x-y)*f(y),y, algorithm="sympy")</code>hausdorffWed, 08 Aug 2018 13:41:12 +0200https://ask.sagemath.org/question/43287/Analytical evaluation of Fermi-Dirac integralshttps://ask.sagemath.org/question/45559/analytical-evaluation-of-fermi-dirac-integrals/It seems that sagemath is unable to calculate Fermic-Dirac type integrals, e. g.
integrate(x^2/(1+ e^x),x,0,oo) =>
limit(1/3*x^3 - x^2*log(e^x + 1) - 2*x*dilog(-e^x) + 2*polylog(3, -e^x), x, +Infinity, minus) + 3/2*zeta(3)
integrate(x^3/(1+ e^x),x,0,oo)==>
-7/120*pi^4 + limit(1/4*x^4 - x^3*log(e^x + 1) - 3*x^2*dilog(-e^x) + 6*x*polylog(3, -e^x) - 6*polylog(4, -e^x), x,
+Infinity, minus)
Normally, the former evaluates to (3*Zeta[3])/2 and the latter to (7*Pi^4)/120, using Mathematica.irizosWed, 27 Feb 2019 14:55:41 +0100https://ask.sagemath.org/question/45559/Sage could be even more clever - How to force the use of 'sympy' backend for simplifying symbolic integrals?https://ask.sagemath.org/question/43392/sage-could-be-even-more-clever-how-to-force-the-use-of-sympy-backend-for-simplifying-symbolic-integrals/Hi there,
I have noticed the following problem:
sage: f = function('f')(x)
sage: var('h')
sage: integrate(exp(h)*exp(x)*f(x),x)
integrate(e^(h + x)*f(x), x)
The workaround seems to be using the `sympy` backend for symbolic integration
sage: integrate(exp(h)*exp(x)*f(x),x,algorithm='sympy')
e^h*integrate(e^x*f(x), x)
which always seems to be a good idea as I learned from @Emmanuel Charpentier over
[here](https://ask.sagemath.org/question/43287/solved-why-does-integratepsiyfyy-return-an-error-but-integratepsityftyy-works/?answer=43297#post-id-43297).
Now I would like to force the use of `algorith='sympy'` for simplifying these `integrate(...)` expressions globally.
Unfortunately, the `simplify()` command does not allow to set this option.
sage: integrate(exp(h)*exp(x)*f(x),x)
integrate(e^(h + x)*f(x), x)
sage: _.simplify()
integrate(e^(h + x)*f(x), x)
**TL;DR** How can I force sage to pull out these type of exponential constants from the integral with the `simplify()` command?
hausdorffThu, 16 Aug 2018 18:54:20 +0200https://ask.sagemath.org/question/43392/Integrate expression involving a formal functionhttps://ask.sagemath.org/question/41415/integrate-expression-involving-a-formal-function/I am trying to integrate expressions involving a formal function $f(x)$:
sage: var('x')
sage: function('f')
It works in some simple cases:
sage: integrate(cos(f(x)) * f(x).diff(), x)
sin(f(x))
However, a slightly more complicated expression is left unchanged:
sage: integrate(x * f(x).diff() + f(x), x)
integrate(x*diff(f(x), x) + f(x), x)
instead of simplifying to $x\ f(x)$.
Is it possible to integrate such expressions in Sage? I tried to use other algorithms (e.g. `algorithm='mathematica_free'`), but I got this traceback:
.local/opt/sage-8.0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in derivative(self, ex, operator)
588 from sage.symbolic.ring import is_SymbolicVariable
589 if self.name_init != "_maxima_init_":
--> 590 raise NotImplementedError
591 args = ex.operands()
592 if (not all(is_SymbolicVariable(v) for v in args) or
so it looks like only Maxima algorithm can be used because the derivative operation cannot be converted to anything else.envypoleTue, 06 Mar 2018 19:41:49 +0100https://ask.sagemath.org/question/41415/Difference between integral(csc(x)) and integral(1/sin(x))?https://ask.sagemath.org/question/40806/difference-between-integralcscx-and-integral1sinx/ integral(csc(x),x) gives -log(cot(x) + csc(x)) as expected. integral(1/sin(x),x) gives -1/2*log(cos(x) + 1) + 1/2*log(cos(x) - 1). Evaluation of the second log is problematic because cos(x)-1 < 0 for all x except n*2pi. Choosing the sympy or maxima algorithms makes no difference.
Also (and this is less reliable) if I perform a substitution t=tan(x/2) by hand in the first case I get ln(t), again as expected. But in the second ln(-t). That maybe my fault but I can't see what I did wrong.
Is there any fundamental difference between asking that same question in two different ways?
NickBaileySat, 27 Jan 2018 16:10:05 +0100https://ask.sagemath.org/question/40806/integrate x^3/(exp(x)-1) between 0 and infinityhttps://ask.sagemath.org/question/37865/integrate-x3expx-1-between-0-and-infinity/If I type
> integrate(x^3/(exp(x)-1),x,0,infinity)
I get
-1/15*pi^4 + limit(-1/4*x^4 + x^3*log(-e^x + 1) + 3*x^2*dilog(e^x) - 6*x*polylog(3, e^x) + 6*polylog(4, e^x), x, +Infinity, minus)
The command numerical_integral(x^3/(exp(x)-1),0,infinity) gives 6.4939394075
I have two questions :
1. How do I evaluate the limit ?
2. The correct answer is pi^4/15(=6.49393940226683) : why
SageMath does not give it with symbolic integration ?
ThanksepimetheusThu, 08 Jun 2017 19:56:33 +0200https://ask.sagemath.org/question/37865/symbolic integrationhttps://ask.sagemath.org/question/36408/symbolic-integration/ If you ask sage to symbolically integrate the following properly, the answer is wrong. Why?
cos(x)/(a*cos(x) + b*sin(x))
[Aside -- the captcha was invisible with firefox 50.1/linux, leading to much teeth-gnashing. Seems to work OK with Chrome. Not happy]bevSun, 29 Jan 2017 05:44:30 +0100https://ask.sagemath.org/question/36408/Two ways of integrating x↦xⁿsin(x) give contradictory results. Bug?https://ask.sagemath.org/question/36185/two-ways-of-integrating-x-xnsinx-give-contradictory-results-bug/**First way:**
var('x,n')
integral(x^n*sin(x),x)
gives just
integrate(x^n*sin(x), x)
not very informative, let us try to add an assumption to get nicer results.
**Second way:**
assume(n,'integer')
integral(x^n*sin(x),x)
gives
1/4*(((-1)^n - 1)*gamma(n + 1, I*x) - ((-1)^n - 1)*gamma(n + 1, -I*x))*(-1)^(-1/2*n)
Uhm, looks better, but... wait, isn't `(-1)^n-1` equal to `0` for even values of `n` ? That would make the whole thing equal to `0` for even `n`.
I = integral(x^n*sin(x),x)
for k in range(10):
print I.subs(n==2*k)
prints only `0`s. Weird, non-zero functions should not have zero integrals.
**Third way :**
Let us try to do the integration with particular values of `n`.
for n in range(5):
print integral(x^n*sin(x),x)
prints
-cos(x)
-x*cos(x) + sin(x)
-(x^2 - 2)*cos(x) + 2*x*sin(x)
-(x^3 - 6*x)*cos(x) + 3*(x^2 - 2)*sin(x)
Looks better, but is clearly different from the previous answer.
**Question:**
I am working on the cloud, with SageMath 7.4 kernel. Is this a bug or did I misunderstood the meaning of the `'integer'`assumption ?
If this is a bug, how should I report it, is posting this question here enough ?
P.S. I did read the [wiki page about reporting bugs](http://doc.sagemath.org/html/en/developer/trac.html#reporting-bugs), but, gosh, is it really necessary to have a google account in order to report a bug ? Both sage-devel and sage-support are on Google Groups. lbWed, 04 Jan 2017 21:44:16 +0100https://ask.sagemath.org/question/36185/integration of matrix-valued functionhttps://ask.sagemath.org/question/31085/integration-of-matrix-valued-function/ Hi,
I want to compute the (in)definite integral of matrix valued function, for example
var('x')
f =matrix([[x,1],[x^2,2]]);
The command
integrate(f,x,0,1)
doesn't work. I expect matrix as a result - integrated by elements
janThu, 26 Nov 2015 13:34:42 +0100https://ask.sagemath.org/question/31085/help with simple integration of piecewise function?https://ask.sagemath.org/question/24887/help-with-simple-integration-of-piecewise-function/ r = var('r')
Piecewise([[(1,2), 1/floor(r)]]).integral(r,1,2)
Gives an error:
Error in lines ...
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables
What am I doing wrong? I note that
Piecewise([[(1,2), 1/floor(r)]]).integral(r)
gives output ``Piecewise defined function with 1 parts, [[(1, 2), r1 |--> integrate(1/floor(r1), r1, 1, r1)]]''.
And that
integrate(1/floor(r1), r1, 1, r1)(2)
gives the same error as the first attempt. Here's the full stacktrace of the error:
EDIT: Thanks. Here's the full stack trace for the error:
File "/Applications/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py", line 833, in integral
return F(b) - F(a)
File "/Applications/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py", line 665, in __call__
return self.functions()[n-1](x0)
File "expression.pyx", line 4391, in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:21933)
File "/Applications/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/callable.py", line 477, in _call_element_
return SR(_the_element.substitute(**d))
File "expression.pyx", line 4242, in sage.symbolic.expression.Expression.substitute (build/cythonized/sage/symbolic/expression.cpp:21183)
File "/Applications/Sage-6.3.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 161, in _eval_
if len(x.variables()) == 1:
File "element.pyx", line 344, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4022)
File "misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1775)
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables'NealSun, 16 Nov 2014 23:35:36 +0100https://ask.sagemath.org/question/24887/Working with formal power serieshttps://ask.sagemath.org/question/10553/working-with-formal-power-series/This is a simplified version of my previous [question](http://ask.sagemath.org/question/3012/integrating-formal-laurent-series).
1) Is it possible to define a formal power series in sage by giving an expression for the n-th coefficient, e.g. as the expression "n" defines the power series 0 + 1 x + 2 x^2 + 3 x^3 + ... n x^n + ... ?
2) Does sage know how to multiply such objects by convolving the terms? Can it anti-differentiate them symbolically?
anilbvFri, 20 Sep 2013 10:17:18 +0200https://ask.sagemath.org/question/10553/integrating formal Laurent serieshttps://ask.sagemath.org/question/10546/integrating-formal-laurent-series/I would like to compute some integrals of products of Laurent series, with the goal of getting an explicit expression for the n-th coefficient of the result. It gets pretty messy so I was hoping that sage could keep track of the details for me. Here are the things I don't know how to do:
1) Define a Laurent series by giving an expression for its n-th coefficient.
2) Formally multiply and integrate Laurent series, producing an explicit expression for the n-th coefficient of the result.
Is this possible? I apologize if some or all of this is explained elsewhere.
EDIT: An example of what I want to do would be to define a power series such as sum(n * x^n,n,0,infinity) and then integrate it and/or multiply it by another power series, resulting in yet another power series whose coefficients I can read off. The O(x^n) notation is not very useful to me since I would like to have an expression for an arbitrary coefficient of that resulting series in terms of n.anilbvWed, 18 Sep 2013 19:39:16 +0200https://ask.sagemath.org/question/10546/integrate cos(x)*cos(2x)*...*cos(mx) via SAGEhttps://ask.sagemath.org/question/10248/integrate-cosxcos2xcosmx-via-sage/I'm going to find $I_m=\int_0^{2\pi} \prod_{k=1}^m cos(kx)\{}dx$, where $m=1,2,3\ldots$
Simple SAGE code:
x=var('x')
f = lambda m,x : prod([cos(k*x) for k in range(1,m+1)])
for m in range(1,15+1):
print m, numerical_integral(f(m,x), 0, 2*pi)[0],integrate(f(m,x),x,0,2*pi).n()
Output:
1 -1.47676658757e-16 0.000000000000000
2 -5.27735962315e-16 0.000000000000000
3 1.57079632679 1.57079632679490
4 0.785398163397 0.785398163397448
5 -2.60536121164e-16 0.000000000000000
6 -1.81559273097e-16 0.000000000000000
7 0.392699081699 0.392699081698724
8 0.343611696486 0.147262155637022
9 -1.72448482421e-16 0.294524311274043
10 -1.8747663502e-16 0.196349540849362
11 0.214757310304 0.312932080728671
12 0.190213617698 0.177941771394734
13 -1.30355375996e-16 0.208621387152447
14 -1.25168280013e-16 0.0859029241215959
15 0.138441766107 0.134223318939994
As you can see numerical answer is right, but result of integrate(...) is right for $m=1,2,\ldots,7$ and then there is some bug.
We can print indefinite integral:
for m in range(7,11+1):
print 'm=',m
print 'Indef_I_m=',integrate(f(m,x),x)
And Output:
m = 7
Indef_I_m = 1/16*x + 1/16*sin(2*x) + 1/32*sin(4*x) + 7/384*sin(6*x) +
7/512*sin(8*x) + 3/320*sin(10*x) + 5/768*sin(12*x) + 5/896*sin(14*x) +
1/256*sin(16*x) + 1/384*sin(18*x) + 1/640*sin(20*x) + 1/704*sin(22*x) +
1/1536*sin(24*x) + 1/1664*sin(26*x) + 1/1792*sin(28*x)
m = 8
Indef_I_m = 3/128*x + 5/256*sin(2*x) + 1/32*sin(3*x) + 5/512*sin(4*x) +
5/768*sin(6*x) + 1/256*sin(8*x) + 1/256*sin(10*x) + 1/256*sin(12*x) +
1/256*sin(14*x) + 1/256*sin(16*x) + 7/2304*sin(18*x) + 3/1280*sin(20*x)
+ 5/2816*sin(22*x) + 1/768*sin(24*x) + 3/3328*sin(26*x) +
1/1792*sin(28*x) + 1/1920*sin(30*x) + 1/4096*sin(32*x) +
1/4352*sin(34*x) + 1/4608*sin(36*x) + 3/32*sin(x)
m = 9
Indef_I_m = 3/64*x + 3/128*sin(2*x) + 23/768*sin(3*x) + 3/256*sin(4*x) +
3/640*sin(5*x) + 1/128*sin(6*x) + 5/1792*sin(7*x) + 5/2304*sin(9*x) +
3/2816*sin(11*x) + 1/832*sin(13*x) + 1/1280*sin(15*x) + 3/4352*sin(17*x)
+ 5/4864*sin(19*x) + 1/1344*sin(21*x) + 3/2944*sin(23*x) +
7/6400*sin(25*x) + 1/1152*sin(27*x) + 3/3712*sin(29*x) +
5/7936*sin(31*x) + 1/2112*sin(33*x) + 3/8960*sin(35*x) +
1/4736*sin(37*x) + 1/4992*sin(39*x) + 1/10496*sin(41*x) +
1/11008*sin(43*x) + 1/11520*sin(45*x) + 23/256*sin(x)
m = 10
Indef_I_m = 1/32*x + 1/64*sin(2*x) + 17/512*sin(3*x) + 1/128*sin(4*x) +
7/2560*sin(5*x) + 1/192*sin(6*x) + 3/1792*sin(7*x) + 1/1152*sin(9*x) +
5/5632*sin(11*x) + 3/6656*sin(13*x) + 1/2560*sin(15*x) +
5/8704*sin(17*x) + 3/9728*sin(19*x) + 1/2688*sin(21*x) +
1/2944*sin(23*x) + 1/6400*sin(25*x) + 1/4608*sin(27*x) +
3/14848*sin(29*x) + 3/15872*sin(31*x) + 5/16896*sin(33*x) +
3/8960*sin(35*x) + 3/9472*sin(37*x) + 1/3328*sin(39*x) +
5/20992*sin(41*x) + 1/5504*sin(43*x) + 1/7680*sin(45*x) +
1/12032*sin(47*x) + 1/12544*sin(49*x) + 1/26112*sin(51*x) +
1/27136*sin(53*x) + 1/28160*sin(55*x) + 13/128*sin(x)
m = 11
Indef_I_m = 51/1024*x + 53/2048*sin(2*x) + 13/768*sin(3*x) + 53/4096*sin(4*x) +
13/1536*sin(6*x) + 1/2048*sin(8*x) + 1/2560*sin(10*x) + 1/3072*sin(12*x)
+ 5/14336*sin(14*x) + 1/4096*sin(16*x) + 5/18432*sin(18*x) +
1/4096*sin(20*x) + 1/5632*sin(22*x) + 5/24576*sin(24*x) +
5/26624*sin(26*x) + 5/28672*sin(28*x) + 1/5120*sin(30*x) +
3/16384*sin(32*x) + 5/34816*sin(34*x) + 1/9216*sin(36*x) +
5/38912*sin(38*x) + 1/10240*sin(40*x) + 1/10752*sin(42*x) +
3/22528*sin(44*x) + 3/23552*sin(46*x) + 1/8192*sin(48*x) +
3/25600*sin(50*x) + 5/53248*sin(52*x) + 1/13824*sin(54*x) +
3/57344*sin(56*x) + 1/29696*sin(58*x) + 1/30720*sin(60*x) +
1/63488*sin(62*x) + 1/65536*sin(64*x) + 1/67584*sin(66*x) +
13/256*sin(x)
so for $m=7$ answer is right compare with [Indef_I_7 via WolframAlpha](http://www.wolframalpha.com/input/?i=integrate+cos%28x%29*cos%282x%29*cos%283x%29*cos%284x%29*cos%285x%29*cos%286x%29*cos%287x%29)
and for $m=8$ answer is incorrect [Indef_I_8 via WolframAlpha](http://www.wolframalpha.com/input/?i=integrate+cos%28x%29*cos%282x%29*cos%283x%29*cos%284x%29*cos%285x%29*cos%286x%29*cos%287x%29*cos%288x%29)
There should be Indef_I_8=$\frac{7x}{128}+\ldots$ and no $\sin(x)$, $\sin(3x)$ in summation, only $\sin(2k)$ for $k=1,2,3,\ldots 18$
Sorry for volumetric calculations !
The question is - Am I right that it is the bug in the symbolic integration?IvanGMon, 17 Jun 2013 13:39:21 +0200https://ask.sagemath.org/question/10248/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/Why does this not integratehttps://ask.sagemath.org/question/9571/why-does-this-not-integrate/why is this integral performed:
forget()
var('n')
assume(n>0)
integrate(1/sqrt(1+x^2*n),x,1,2)
i.e. I get:
-arcsinh(sqrt(n))/sqrt(n) + arcsinh(2*sqrt(n))/sqrt(n)
while this is not
forget()
var('n')
assume(n>0)
integrate(1/sqrt(1+x^2/n),x,1,2)
MarkWed, 28 Nov 2012 09:06:22 +0100https://ask.sagemath.org/question/9571/mistake in a indefinite integralhttps://ask.sagemath.org/question/9547/mistake-in-a-indefinite-integral/Hi,
I'm trying to compute the integral:
>integral(log(cot(x)-1),x,0,pi/4)
Sage (with version 5.4 and previous ones) tell that the integral is $-\infty$. But the integral converges, and it is is equal to $\frac{\pi\log(2)}8$.
I think this can be a bug. Maybe it is a Maxima issue, but it should be interesting to find where the bug is, and correct it, if possible.mathematicboyMon, 19 Nov 2012 12:02:30 +0100https://ask.sagemath.org/question/9547/Implementing the basic Fourier-Transformationhttps://ask.sagemath.org/question/9469/implementing-the-basic-fourier-transformation/Hi there!
I'm currently plaing around with sage and I'm really excited about it.
I'd love to do my computations at university and home with a neat opensource-tool instead of the higly prices closed competitors.
Now, the problem I am facing is the symbolif computation of a fourier transformation.
Below is my current naive approach (I'm still learning fourier and complex mathematics, but with large interest!)
x,w,f_0,t = var("x,w,f_0,t")
w = 2*pi*f_0
x(t) = sin(w*t)
integrate(x*exp(-I*w*t),t, -oo, oo)
which results in the following (obviously equal) result:
integrate(e^(-2*I*pi*f_0*t)*sin(2*pi*f_0*t), t, -Infinity, +Infinity)
My expectiation would be an equation without the t (since it has been substituted through integration) and an floating f_0 which I can set according to my desired sine frequency.
Please, could someone tell me, what exactly I am missing here?
Greetings
JakobJakob HolderbaumThu, 25 Oct 2012 06:43:37 +0200https://ask.sagemath.org/question/9469/