ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 24 Jul 2019 08:17:59 -0500Problem with integrating the expression of Mhttp://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/ Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?
c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.Mon, 22 Jul 2019 03:43:22 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/Comment by Sha for <p>Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?</p>
<pre><code>c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
</code></pre>
<p>I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.</p>
http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47247#post-id-47247@emmanuel definitely not homework but research paper that I am leading at the moment. my co-author got different results than mine. so we thought of using Sage to verify the results.Tue, 23 Jul 2019 00:28:17 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47247#post-id-47247Comment by Sha for <p>Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?</p>
<pre><code>c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
</code></pre>
<p>I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.</p>
http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47246#post-id-47246@rburing c is any value in the interval [-0.9, 0.9], which i plan to vary later at the end after the integration and differentiation.Tue, 23 Jul 2019 00:26:45 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47246#post-id-47246Comment by Emmanuel Charpentier for <p>Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?</p>
<pre><code>c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
</code></pre>
<p>I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.</p>
http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47245#post-id-47245Homework ?
Works for me using Sage 8.9.beta3 using Python3. `rburning`'s hint is good, but trying other integrators ("sympy", "giac", "mathematica_free") might give you other ideas... Check your results by rederiving...Mon, 22 Jul 2019 16:31:47 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47245#post-id-47245Comment by rburing for <p>Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?</p>
<pre><code>c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
</code></pre>
<p>I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.</p>
http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47241#post-id-47241What do you assume about $c$? Try making it explicit, using `assume` before `integrate`.Mon, 22 Jul 2019 07:29:14 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?comment=47241#post-id-47241Answer by Emmanuel Charpentier for <p>Hi. I have the following code that I want to integrate and differentiate, but I am stuck at the expression of M, where it is unable to integrate. Is my coding wrong?</p>
<pre><code>c,t = var('c t')
Pi = RR.pi()
G=integrate(sqrt(1-t^2)*(t+c),t,-0.9,0.9);G
H=G.diff(c);H
L=integrate(-(t+c)/(sqrt(1-t^2)),t,-0.9,0.9);L
M=integrate(1/(sqrt(1-t^2)*(t-c)),t,-0.9,0.9);M #cannot seem to integrate this wrt to t
I=(c^2-1)*(L+(1-c^2)*M);I #equation I that involves M
P=I.diff(c);P #differentiate I wrt to c to obtain equation P
</code></pre>
<p>I have tried integrating M by hand which gives me a closed-form involving log function, but I can't seem to integrate it here using Sage.</p>
http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?answer=47256#post-id-47256Well, in this case, let's look at your expression's *antiderivative* (Sage is known to have some infelicities in *definite* integration). Sage's default integrator (i. e. `maxima`) needs to know if $c^2-1>0$ ; account for that as well as for other Sage's integrators :
(c,t)=var("c, t")
E=sqrt(1-t^2)*(t+c)
Sols={}
with assuming(c>-1,c<1):Sols.update({"Mn":E.integrate(t)})
with assuming(c<-1):Sols.update({"Mp":E.integrate(t)})
Sols.update({"Mf":E.integrate(t, algorithm="fricas")})
Sols.update({"Mg":E.integrate(t, algorithm="giac")})
Sols.update({"Mm":mathematica.Integrate(E,t).sage()}
Sols.update({"Ms":E.integrate(t, algorithm="sympy")}))
We have now six expressions (four pairwise distinct expressions) for a primitive of your expression $E$:
Sols
{'Mn': 1/2*sqrt(-t^2 + 1)*c*t + 1/2*c*arcsin(t) - 1/3*(-t^2 + 1)^(3/2),
'Mp': 1/2*sqrt(-t^2 + 1)*c*t + 1/2*c*arcsin(t) - 1/3*(-t^2 + 1)^(3/2),
'Mf': 1/6*(3*c*t^5 + 2*t^6 - 15*c*t^3 - 12*t^4 + 12*c*t + 12*t^2 - 6*(3*c*t^2 - (c*t^2 - 4*c)*sqrt(-t^2 + 1) - 4*c)*arctan((sqrt(-t^2 + 1) - 1)/t) + 3*(3*c*t^3 + 2*t^4 - 4*c*t - 4*t^2)*sqrt(-t^2 + 1))/(3*t^2 - (t^2 - 4)*sqrt(-t^2 + 1) - 4),
'Mg': 1/2*c*arcsin(t) + 1/6*((3*c + 2*t)*t - 2)*sqrt(-t^2 + 1),
'Mm': 1/2*c*arcsin(t) + 1/6*(3*c*t + 2*t^2 - 2)*sqrt(-t^2 + 1),
'Ms': 1/2*sqrt(-t^2 + 1)*c*t + 1/3*sqrt(-t^2 + 1)*t^2 + 1/2*c*arcsin(t) - 1/3*sqrt(-t^2 + 1)}
More easily seen and understood via `\LaTeX`:
$$ \begin{align} Mn &: \\frac{1}{2} \\, \\sqrt{-t^{2} + 1} c t + \\frac{1}{2} \\, c \\arcsin\\left(t\\right) - \\frac{1}{3} \\, {\\left(-t^{2} + 1\\right)}^{\\frac{3}{2}}\\\\Mp &: \\frac{1}{2} \\, \\sqrt{-t^{2} + 1} c t + \\frac{1}{2} \\, c \\arcsin\\left(t\\right) - \\frac{1}{3} \\, {\\left(-t^{2} + 1\\right)}^{\\frac{3}{2}}\\\\Mf &: \\frac{3 \\, c t^{5} + 2 \\, t^{6} - 15 \\, c t^{3} - 12 \\, t^{4} + 12 \\, c t + 12 \\, t^{2} - 6 \\, {\\left(3 \\, c t^{2} - {\\left(c t^{2} - 4 \\, c\\right)} \\sqrt{-t^{2} + 1} - 4 \\, c\\right)} \\arctan\\left(\\frac{\\sqrt{-t^{2} + 1} - 1}{t}\\right) + 3 \\, {\\left(3 \\, c t^{3} + 2 \\, t^{4} - 4 \\, c t - 4 \\, t^{2}\\right)} \\sqrt{-t^{2} + 1}}{6 \\, {\\left(3 \\, t^{2} - {\\left(t^{2} - 4\\right)} \\sqrt{-t^{2} + 1} - 4\\right)}}\\\\Mg &: \\frac{1}{2} \\, c \\arcsin\\left(t\\right) + \\frac{1}{6} \\, {\\left({\\left(3 \\, c + 2 \\, t\\right)} t - 2\\right)} \\sqrt{-t^{2} + 1}\\\\Mm &: \\frac{1}{2} \\, c \\arcsin\\left(t\\right) + \\frac{1}{6} \\, {\\left(3 \\, c t + 2 \\, t^{2} - 2\\right)} \\sqrt{-t^{2} + 1}\\\\Ms &: \\frac{1}{2} \\, \\sqrt{-t^{2} + 1} c t + \\frac{1}{3} \\, \\sqrt{-t^{2} + 1} t^{2} + \\frac{1}{2} \\, c \\arcsin\\left(t\\right) - \\frac{1}{3} \\, \\sqrt{-t^{2} + 1} \end{align}$$
(one can ensure that `maxima`'s solution for $c>1$ is identical to the one found for $c<-1$:
with assuming(c>1): bool(E.integrate(t)==Sols.get("Mp"))
True).
But all these expressions turn out to derivate to $E$:
[(Sols.get(u).diff(t)/E).canonicalize_radical() for u in Sols.keys()]
[1, 1, 1, 1, 1, 1]
Different integrators have different strategies for integration, leading to different primitives. Barring discontinuities, these four expressions should differ by a constant.Wed, 24 Jul 2019 08:17:59 -0500http://ask.sagemath.org/question/47240/problem-with-integrating-the-expression-of-m/?answer=47256#post-id-47256