1 | initial version |
Eating my own dogfood :
sage: var("A, B, u", domain="real")
(A, B, u)
sage: var("n", domain="integer")
n
sage: Itg=(cos(n*u)+I*sin(n*u))/((A+B*sin(u))^3-1)
Note that we replace $e^{inu}$ by its de Moivre expansion, to avoid repeating an awkward substitution.
Let's see if this expression has poles in the real segment $(-\pi\ \pi)$:
sage: var("t", domain="real")
t
sage: assume(t>=-1, t<=1)
sage: Itg.denominator().subs(sin(u)==t).solve(t)
So, yes, depending on the values of $A$ and $B$, this expression might have poles (points for which the denominator is null) in the integration path. Integrating there would be a problem... left to the reader as an exercise.
Preliminary trials showed that mots of the integrators available with Sage
have problems with this kind of expression :
Maxima
(default) will integrate some cases, and fail with nosy questions about some nosy questions about (complicated) relations between A and B, not cured by adding the relevant assumptions.
Sympy
can be extremely slow, and may return expressions without direct translation to Sage
, thus requiring manual preparation (direct calls to sympy
methods), and surgical extraction and conversion of the result.
Giac
usually fails to return.
Fricas
returns very large Fricas expression, not translatable in Sage
. No surgery available here, unless you do all the work in Fricas
(not fun).
algorithm="mathematica_free"
may or may not work. It often fails for an absence of results in WolframAlpha
's answer; this seems to be more or less random (WolframAlpha
's availability ?).
However, Mathematica
seems to work. The best way seems to embed calls to Mathematica in management code in Sage
, returning Sage
objects.
A few attempts show that finding primitives for these functions is much easier that finding definite integrals. It seems prudent to first find the primitives, evaluate them and, if no bobbytrap (e. g. poles, bizarre integration results, etc...) is found, find the definite integral by taking appropriate limits.
We may help Mathematica
by more or less pre-processing the integrand (e.g. separating the real and imaginary parts) :
sage: %time foo=[{n:v, "C":mathematica.Integrate(cos(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u), "S":mathematica.Integrate(I*sin(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u)} for v in (-3..3)]
CPU times: user 82.4 ms, sys: 4.03 ms, total: 86.4 ms
Wall time: 8.7 s
sage: %time bar=[{n:v, "P":mathematica.Integrate((cos(v*u)+I*sin(v*u)).trig_expan
....: d()/((A+B*sin(u))^3-1), u)} for v in (-3..3)]
CPU times: user 47.1 ms, sys: 7.97 ms, total: 55 ms
Wall time: 8.31 s
sage: %time gee=[{n:v, "P":mathematica.Integrate(Itg.subs(n==v).trig_expand(), u)
....: } for v in (-3..3)]
CPU times: user 75.4 ms, sys: 0 ns, total: 75.4 ms
Wall time: 8.22 s
The computing times are close. However, the complexity of the answers are not the same (not illustrated here : some expression don't fit a=on a 19"x19" bedsheet. See for yourself...). Finding the limits is usually slow, and may be problematic in some cases. Finding the limits from separate integrations of real and imaginary parts may be easier...
Substituting the original constants and variables in our "big constants" $A$ and $B$ is left as an exercise to the reader.
So if you can somehow access Mathematica
, this problem can be solved by Sage
.
HTH,
2 | No.2 Revision |
EDIT : I checked that none of the integrators available to/via Sage
(including Rubi installed in Mathematica) can explicitly compute $\displaystyle\int\frac{e^{iru}}{((A+B\sin u)) 3 -1}\,du$ where r is real. However, as already noted, using the hint that $n$ is a integer, solutions exist to compute this integral for any given value of $n$.
Eating my own dogfood :
sage: var("A, B, u", domain="real")
(A, B, u)
sage: var("n", domain="integer")
n
sage: Itg=(cos(n*u)+I*sin(n*u))/((A+B*sin(u))^3-1)
Note that we replace $e^{inu}$ by its de Moivre expansion, to avoid repeating an awkward substitution.
Let's see if this expression has poles in the real segment $(-\pi\ \pi)$:
sage: var("t", domain="real")
t
sage: assume(t>=-1, t<=1)
sage: Itg.denominator().subs(sin(u)==t).solve(t)
So, yes, depending on the values of $A$ and $B$, this expression might have poles (points for which the denominator is null) in the integration path. Integrating there would be a problem... left to the reader as an exercise.
Preliminary trials showed that mots of the integrators available with Sage
have problems with this kind of expression :
Maxima
(default) will integrate some cases, and fail with nosy questions about some nosy questions about (complicated) relations between A and B, not cured by adding the relevant assumptions.
Sympy
can be extremely slow, and may return expressions without direct translation to Sage
, thus requiring manual preparation (direct calls to sympy
methods), and surgical extraction and conversion of the result.
Giac
usually fails to return.
Fricas
returns very large Fricas expression, not translatable in Sage
. No surgery available here, unless you do all the work in Fricas
(not fun).
algorithm="mathematica_free"
may or may not work. It often fails for an absence of results in WolframAlpha
's answer; this seems to be more or less random (WolframAlpha
's availability ?).
However, Mathematica
seems to work. The best way seems to embed calls to Mathematica in management code in Sage
, returning Sage
objects.
A few attempts show that finding primitives for these functions is much easier that finding definite integrals. It seems prudent to first find the primitives, evaluate them and, if no bobbytrap (e. g. poles, bizarre integration results, etc...) is found, find the definite integral by taking appropriate limits.
We may help Mathematica
by more or less pre-processing the integrand (e.g. separating the real and imaginary parts) :
sage: %time foo=[{n:v, "C":mathematica.Integrate(cos(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u), "S":mathematica.Integrate(I*sin(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u)} for v in (-3..3)]
CPU times: user 82.4 ms, sys: 4.03 ms, total: 86.4 ms
Wall time: 8.7 s
sage: %time bar=[{n:v, "P":mathematica.Integrate((cos(v*u)+I*sin(v*u)).trig_expan
....: d()/((A+B*sin(u))^3-1), u)} for v in (-3..3)]
CPU times: user 47.1 ms, sys: 7.97 ms, total: 55 ms
Wall time: 8.31 s
sage: %time gee=[{n:v, "P":mathematica.Integrate(Itg.subs(n==v).trig_expand(), u)
....: } for v in (-3..3)]
CPU times: user 75.4 ms, sys: 0 ns, total: 75.4 ms
Wall time: 8.22 s
The computing times are close. However, the complexity of the answers are not the same (not illustrated here : some expression don't fit a=on a 19"x19" bedsheet. See for yourself...). Finding the limits is usually slow, and may be problematic in some cases. Finding the limits from separate integrations of real and imaginary parts may be easier...
Substituting the original constants and variables in our "big constants" $A$ and $B$ is left as an exercise to the reader.
So if you can somehow access Mathematica
, this problem can be solved by Sage
.
EDIT : I have not yet been able to get any of these integrators to create a closed-form formula for an arbitrary $n$ ; all the successes I got where for specific values of $n$.
EDIT : my test case (computing $c_i$ for $i$ integer in $[-3\ 3]$) is stupid, because it doesn't exploit the fact that, all our variables being reals, the values of $c_j$ and $c_{-j}$ should be conjugate...
HTH,
3 | No.3 Revision |
EDIT : I checked that none of the integrators available to/via Sage
(including Rubi installed in Mathematica) can explicitly compute $\displaystyle\int\frac{e^{iru}}{((A+B\sin u)) 3 u))^3 -1}\,du$ where r is real. However, as already noted, using the hint that $n$ is a integer, solutions exist to compute this integral for any given value of $n$.
Eating my own dogfood :
sage: var("A, B, u", domain="real")
(A, B, u)
sage: var("n", domain="integer")
n
sage: Itg=(cos(n*u)+I*sin(n*u))/((A+B*sin(u))^3-1)
Note that we replace $e^{inu}$ by its de Moivre expansion, to avoid repeating an awkward substitution.
Let's see if this expression has poles in the real segment $(-\pi\ \pi)$:
sage: var("t", domain="real")
t
sage: assume(t>=-1, t<=1)
sage: Itg.denominator().subs(sin(u)==t).solve(t)
So, yes, depending on the values of $A$ and $B$, this expression might have poles (points for which the denominator is null) in the integration path. Integrating there would be a problem... left to the reader as an exercise.
Preliminary trials showed that mots of the integrators available with Sage
have problems with this kind of expression :
Maxima
(default) will integrate some cases, and fail with nosy questions about some nosy questions about (complicated) relations between A and B, not cured by adding the relevant assumptions.
Sympy
can be extremely slow, and may return expressions without direct translation to Sage
, thus requiring manual preparation (direct calls to sympy
methods), and surgical extraction and conversion of the result.
Giac
usually fails to return.
Fricas
returns very large Fricas expression, not translatable in Sage
. No surgery available here, unless you do all the work in Fricas
(not fun).
algorithm="mathematica_free"
may or may not work. It often fails for an absence of results in WolframAlpha
's answer; this seems to be more or less random (WolframAlpha
's availability ?).
However, Mathematica
seems to work. The best way seems to embed calls to Mathematica in management code in Sage
, returning Sage
objects.
A few attempts show that finding primitives for these functions is much easier that finding definite integrals. It seems prudent to first find the primitives, evaluate them and, if no bobbytrap (e. g. poles, bizarre integration results, etc...) is found, find the definite integral by taking appropriate limits.
We may help Mathematica
by more or less pre-processing the integrand (e.g. separating the real and imaginary parts) :
sage: %time foo=[{n:v, "C":mathematica.Integrate(cos(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u), "S":mathematica.Integrate(I*sin(v*u).trig_expand()/((A+B*sin
....: (u))^3-1), u)} for v in (-3..3)]
CPU times: user 82.4 ms, sys: 4.03 ms, total: 86.4 ms
Wall time: 8.7 s
sage: %time bar=[{n:v, "P":mathematica.Integrate((cos(v*u)+I*sin(v*u)).trig_expan
....: d()/((A+B*sin(u))^3-1), u)} for v in (-3..3)]
CPU times: user 47.1 ms, sys: 7.97 ms, total: 55 ms
Wall time: 8.31 s
sage: %time gee=[{n:v, "P":mathematica.Integrate(Itg.subs(n==v).trig_expand(), u)
....: } for v in (-3..3)]
CPU times: user 75.4 ms, sys: 0 ns, total: 75.4 ms
Wall time: 8.22 s
The computing times are close. However, the complexity of the answers are not the same (not illustrated here : some expression don't fit a=on a 19"x19" bedsheet. See for yourself...). Finding the limits is usually slow, and may be problematic in some cases. Finding the limits from separate integrations of real and imaginary parts may be easier...
Substituting the original constants and variables in our "big constants" $A$ and $B$ is left as an exercise to the reader.
So if you can somehow access Mathematica
, this problem can be solved by Sage
.
EDIT : I have not yet been able to get any of these integrators to create a closed-form formula for an arbitrary $n$ ; all the successes I got where for specific values of $n$.
EDIT : my test case (computing $c_i$ for $i$ integer in $[-3\ 3]$) is stupid, because it doesn't exploit the fact that, all our variables being reals, the values of $c_j$ and $c_{-j}$ should be conjugate...
HTH,