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.Tue, 22 Jun 2021 01:03:13 +0200Problem by finding an integralhttps://ask.sagemath.org/question/57555/problem-by-finding-an-integral/I have to find the integral of `x*sqrt(x + 1) dx`.
By hand, I found `(2/3)*x*(x + 1)^(3/2) – (4/15)*(x + 1)^(5/2) + c`.
By SageMath I found `-(2/3)*(x + 1)^(3/2) + (2/15)*(x + 1)^(5/2)`.
The SageMath code is simple:
x = var('x')
f = x*sqrt(x + 1)
fi = integral(f, x)
print(latex(fi))
Which is the error?Sat, 12 Jun 2021 10:45:13 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/Answer by rburing for <p>I have to find the integral of <code>x*sqrt(x + 1) dx</code>.</p>
<p>By hand, I found <code>(2/3)*x*(x + 1)^(3/2) – (4/15)*(x + 1)^(5/2) + c</code>.</p>
<p>By SageMath I found <code>-(2/3)*(x + 1)^(3/2) + (2/15)*(x + 1)^(5/2)</code>.</p>
<p>The SageMath code is simple: </p>
<pre><code>x = var('x')
f = x*sqrt(x + 1)
fi = integral(f, x)
print(latex(fi))
</code></pre>
<p>Which is the error?</p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?answer=57556#post-id-57556The SageMath result (output of your code in SageMath 9.2) has coefficient a $2/5$ instead of the $2/15$ you claim:
sage: fi
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
Then it agrees with your hand calculation, e.g. because for $z = \sqrt{x+1}$ we have $$\frac{2}{5} z^5 - \frac{2}{3} z^3= \frac{2}{3}(z^2-1)z^3 - \frac{4}{15}z^5.$$Tue, 15 Jun 2021 14:37:46 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?answer=57556#post-id-57556Comment by slelievre for <p>The SageMath result (output of your code in SageMath 9.2) has coefficient a $2/5$ instead of the $2/15$ you claim:</p>
<pre><code>sage: fi
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
</code></pre>
<p>Then it agrees with your hand calculation, e.g. because for $z = \sqrt{x+1}$ we have $$\frac{2}{5} z^5 - \frac{2}{3} z^3= \frac{2}{3}(z^2-1)z^3 - \frac{4}{15}z^5.$$</p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57656#post-id-57656You can accept rburing's answer by clicking the check mark next to it below its score.Tue, 22 Jun 2021 01:03:13 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57656#post-id-57656Comment by Spyridon Kanavos for <p>The SageMath result (output of your code in SageMath 9.2) has coefficient a $2/5$ instead of the $2/15$ you claim:</p>
<pre><code>sage: fi
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
</code></pre>
<p>Then it agrees with your hand calculation, e.g. because for $z = \sqrt{x+1}$ we have $$\frac{2}{5} z^5 - \frac{2}{3} z^3= \frac{2}{3}(z^2-1)z^3 - \frac{4}{15}z^5.$$</p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57612#post-id-57612Thank you! Thanks a lot!Fri, 18 Jun 2021 08:55:21 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57612#post-id-57612Answer by slelievre for <p>I have to find the integral of <code>x*sqrt(x + 1) dx</code>.</p>
<p>By hand, I found <code>(2/3)*x*(x + 1)^(3/2) – (4/15)*(x + 1)^(5/2) + c</code>.</p>
<p>By SageMath I found <code>-(2/3)*(x + 1)^(3/2) + (2/15)*(x + 1)^(5/2)</code>.</p>
<p>The SageMath code is simple: </p>
<pre><code>x = var('x')
f = x*sqrt(x + 1)
fi = integral(f, x)
print(latex(fi))
</code></pre>
<p>Which is the error?</p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?answer=57580#post-id-57580Both answers are correct.
To see it by hand, we can use:
- $(x + 1)^{5/2} = (x + 1) (x + 1)^{3/2} = x (x + 1)^{3/2} + (x + 1)^{3/2}$
- $(x + 1)^{3/2} = (x + 1) (x + 1)^{1/2} = x (x + 1)^{1/2} + (x + 1)^{1/2}$
to express both as linear combinations of $(x + 1)^{1/2}$,
$x (x + 1)^{1/2}$ and $x^2 (x + 1)^{1/2}$.
To see it with Sage, we can
- ask Sage whether the two different expressions in fact agree
- differentiate both and compare them
- plot the functions to visually check whether they agree
Define the function to integrate:
sage: x = var('x')
sage: f = x*sqrt(x + 1)
sage: f
sqrt(x + 1)*x
Compute a primitive (aka antiderivative) with Sage:
sage: F = integral(f, x)
sage: F
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
The primitive you computed (up to a constant):
sage: G = (2/3)*x*(x + 1)^(3/2) - (4/15)*(x + 1)^(5/2)
sage: G
-4/15*(x + 1)^(5/2) + 2/3*(x + 1)^(3/2)*x
Check that they agree:
sage: bool(F == G)
True
Check they have the same derivative:
sage: g = G.diff(x)
sage: g
sqrt(x + 1)*x
sage: ff = F.diff(x)
sage: ff
(x + 1)^(3/2) - sqrt(x + 1)
sage: bool(g == ff)
True
Or more visually, compare the plots of `F` and `G` (or `f` and `ff`):
sage: pF = plot(F, (-1, 1.6), color='firebrick')
sage: pG = plot(G, (-1, 1.6), color='steelblue')
sage: p = graphics_array([pF, pG, pF + pG])
sage: p.show(figsize=(7, 3))
Launched png viewer for Graphics Array of size 1 x 3
![Plot two functions with Sage and check they are the same](/upfiles/16237960945034307.png)Wed, 16 Jun 2021 00:29:03 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?answer=57580#post-id-57580Comment by Spyridon Kanavos for <p>Both answers are correct.</p>
<p>To see it by hand, we can use:</p>
<ul>
<li>$(x + 1)^{5/2} = (x + 1) (x + 1)^{3/2} = x (x + 1)^{3/2} + (x + 1)^{3/2}$</li>
<li>$(x + 1)^{3/2} = (x + 1) (x + 1)^{1/2} = x (x + 1)^{1/2} + (x + 1)^{1/2}$</li>
</ul>
<p>to express both as linear combinations of $(x + 1)^{1/2}$,
$x (x + 1)^{1/2}$ and $x^2 (x + 1)^{1/2}$.</p>
<p>To see it with Sage, we can</p>
<ul>
<li>ask Sage whether the two different expressions in fact agree</li>
<li>differentiate both and compare them</li>
<li>plot the functions to visually check whether they agree</li>
</ul>
<p>Define the function to integrate:</p>
<pre><code>sage: x = var('x')
sage: f = x*sqrt(x + 1)
sage: f
sqrt(x + 1)*x
</code></pre>
<p>Compute a primitive (aka antiderivative) with Sage:</p>
<pre><code>sage: F = integral(f, x)
sage: F
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
</code></pre>
<p>The primitive you computed (up to a constant):</p>
<pre><code>sage: G = (2/3)*x*(x + 1)^(3/2) - (4/15)*(x + 1)^(5/2)
sage: G
-4/15*(x + 1)^(5/2) + 2/3*(x + 1)^(3/2)*x
</code></pre>
<p>Check that they agree:</p>
<pre><code>sage: bool(F == G)
True
</code></pre>
<p>Check they have the same derivative:</p>
<pre><code>sage: g = G.diff(x)
sage: g
sqrt(x + 1)*x
sage: ff = F.diff(x)
sage: ff
(x + 1)^(3/2) - sqrt(x + 1)
sage: bool(g == ff)
True
</code></pre>
<p>Or more visually, compare the plots of <code>F</code> and <code>G</code> (or <code>f</code> and <code>ff</code>):</p>
<pre><code>sage: pF = plot(F, (-1, 1.6), color='firebrick')
sage: pG = plot(G, (-1, 1.6), color='steelblue')
sage: p = graphics_array([pF, pG, pF + pG])
sage: p.show(figsize=(7, 3))
Launched png viewer for Graphics Array of size 1 x 3
</code></pre>
<p><img src="/upfiles/16237960945034307.png" alt="Plot two functions with Sage and check they are the same"></p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57647#post-id-57647Yeah, the problem probably has to do with the version. I uninstalled the 8.0 version and I installed the 9.3 one. Now everything is o.k.
Thanks a lot!Mon, 21 Jun 2021 19:36:59 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57647#post-id-57647Comment by slelievre for <p>Both answers are correct.</p>
<p>To see it by hand, we can use:</p>
<ul>
<li>$(x + 1)^{5/2} = (x + 1) (x + 1)^{3/2} = x (x + 1)^{3/2} + (x + 1)^{3/2}$</li>
<li>$(x + 1)^{3/2} = (x + 1) (x + 1)^{1/2} = x (x + 1)^{1/2} + (x + 1)^{1/2}$</li>
</ul>
<p>to express both as linear combinations of $(x + 1)^{1/2}$,
$x (x + 1)^{1/2}$ and $x^2 (x + 1)^{1/2}$.</p>
<p>To see it with Sage, we can</p>
<ul>
<li>ask Sage whether the two different expressions in fact agree</li>
<li>differentiate both and compare them</li>
<li>plot the functions to visually check whether they agree</li>
</ul>
<p>Define the function to integrate:</p>
<pre><code>sage: x = var('x')
sage: f = x*sqrt(x + 1)
sage: f
sqrt(x + 1)*x
</code></pre>
<p>Compute a primitive (aka antiderivative) with Sage:</p>
<pre><code>sage: F = integral(f, x)
sage: F
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
</code></pre>
<p>The primitive you computed (up to a constant):</p>
<pre><code>sage: G = (2/3)*x*(x + 1)^(3/2) - (4/15)*(x + 1)^(5/2)
sage: G
-4/15*(x + 1)^(5/2) + 2/3*(x + 1)^(3/2)*x
</code></pre>
<p>Check that they agree:</p>
<pre><code>sage: bool(F == G)
True
</code></pre>
<p>Check they have the same derivative:</p>
<pre><code>sage: g = G.diff(x)
sage: g
sqrt(x + 1)*x
sage: ff = F.diff(x)
sage: ff
(x + 1)^(3/2) - sqrt(x + 1)
sage: bool(g == ff)
True
</code></pre>
<p>Or more visually, compare the plots of <code>F</code> and <code>G</code> (or <code>f</code> and <code>ff</code>):</p>
<pre><code>sage: pF = plot(F, (-1, 1.6), color='firebrick')
sage: pG = plot(G, (-1, 1.6), color='steelblue')
sage: p = graphics_array([pF, pG, pF + pG])
sage: p.show(figsize=(7, 3))
Launched png viewer for Graphics Array of size 1 x 3
</code></pre>
<p><img src="/upfiles/16237960945034307.png" alt="Plot two functions with Sage and check they are the same"></p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57615#post-id-57615Oh, I see. I would recommend upgrading to Sage 9.3.
When I run Sage 8.0 I get this:
sage: x = var('x')
sage: f = x*sqrt(x + 1)
sage: f
sqrt(x + 1)*x
sage: F = integral(f, x)
sage: F
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
Do you really get `(2/15)`?Fri, 18 Jun 2021 09:56:44 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57615#post-id-57615Comment by Spyridon Kanavos for <p>Both answers are correct.</p>
<p>To see it by hand, we can use:</p>
<ul>
<li>$(x + 1)^{5/2} = (x + 1) (x + 1)^{3/2} = x (x + 1)^{3/2} + (x + 1)^{3/2}$</li>
<li>$(x + 1)^{3/2} = (x + 1) (x + 1)^{1/2} = x (x + 1)^{1/2} + (x + 1)^{1/2}$</li>
</ul>
<p>to express both as linear combinations of $(x + 1)^{1/2}$,
$x (x + 1)^{1/2}$ and $x^2 (x + 1)^{1/2}$.</p>
<p>To see it with Sage, we can</p>
<ul>
<li>ask Sage whether the two different expressions in fact agree</li>
<li>differentiate both and compare them</li>
<li>plot the functions to visually check whether they agree</li>
</ul>
<p>Define the function to integrate:</p>
<pre><code>sage: x = var('x')
sage: f = x*sqrt(x + 1)
sage: f
sqrt(x + 1)*x
</code></pre>
<p>Compute a primitive (aka antiderivative) with Sage:</p>
<pre><code>sage: F = integral(f, x)
sage: F
2/5*(x + 1)^(5/2) - 2/3*(x + 1)^(3/2)
</code></pre>
<p>The primitive you computed (up to a constant):</p>
<pre><code>sage: G = (2/3)*x*(x + 1)^(3/2) - (4/15)*(x + 1)^(5/2)
sage: G
-4/15*(x + 1)^(5/2) + 2/3*(x + 1)^(3/2)*x
</code></pre>
<p>Check that they agree:</p>
<pre><code>sage: bool(F == G)
True
</code></pre>
<p>Check they have the same derivative:</p>
<pre><code>sage: g = G.diff(x)
sage: g
sqrt(x + 1)*x
sage: ff = F.diff(x)
sage: ff
(x + 1)^(3/2) - sqrt(x + 1)
sage: bool(g == ff)
True
</code></pre>
<p>Or more visually, compare the plots of <code>F</code> and <code>G</code> (or <code>f</code> and <code>ff</code>):</p>
<pre><code>sage: pF = plot(F, (-1, 1.6), color='firebrick')
sage: pG = plot(G, (-1, 1.6), color='steelblue')
sage: p = graphics_array([pF, pG, pF + pG])
sage: p.show(figsize=(7, 3))
Launched png viewer for Graphics Array of size 1 x 3
</code></pre>
<p><img src="/upfiles/16237960945034307.png" alt="Plot two functions with Sage and check they are the same"></p>
https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57611#post-id-57611Excellent! Very interesting answer. Otherwise, I have an older version: Sage 8.0Fri, 18 Jun 2021 08:53:55 +0200https://ask.sagemath.org/question/57555/problem-by-finding-an-integral/?comment=57611#post-id-57611