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.Sat, 15 Aug 2020 22:16:15 +0200Error when trying to integratehttps://ask.sagemath.org/question/53018/error-when-trying-to-integrate/This is what I want to do in Sage. It can be done very easily in Desmos. https://www.desmos.com/calculator/7ocj57rixb
I am just trying to do this integral in Sage. When I do it the answer I get is
f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)
N(definite_integral(f(x), x, 6, 23))
5.35572539176154Fri, 14 Aug 2020 23:36:56 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/Comment by John Palmieri for <p>This is what I want to do in Sage. It can be done very easily in Desmos. <a href="https://www.desmos.com/calculator/7ocj57rixb">https://www.desmos.com/calculator/7oc...</a></p>
<p>I am just trying to do this integral in Sage. When I do it the answer I get is</p>
<p>f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)</p>
<p>N(definite_integral(f(x), x, 6, 23))</p>
<p>5.35572539176154</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53021#post-id-53021Don't use "N": just use `2*pi` and `exp(...)`.Sat, 15 Aug 2020 02:40:30 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53021#post-id-53021Comment by Alex89 for <p>This is what I want to do in Sage. It can be done very easily in Desmos. <a href="https://www.desmos.com/calculator/7ocj57rixb">https://www.desmos.com/calculator/7oc...</a></p>
<p>I am just trying to do this integral in Sage. When I do it the answer I get is</p>
<p>f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)</p>
<p>N(definite_integral(f(x), x, 6, 23))</p>
<p>5.35572539176154</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53029#post-id-53029I did the changes, now I get a wrong answer.Sat, 15 Aug 2020 11:17:28 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53029#post-id-53029Comment by John Palmieri for <p>This is what I want to do in Sage. It can be done very easily in Desmos. <a href="https://www.desmos.com/calculator/7ocj57rixb">https://www.desmos.com/calculator/7oc...</a></p>
<p>I am just trying to do this integral in Sage. When I do it the answer I get is</p>
<p>f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)</p>
<p>N(definite_integral(f(x), x, 6, 23))</p>
<p>5.35572539176154</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53033#post-id-53033I think the problem is parentheses, not Sage. `1/3.33 * sqrt(2*pi)` is equal to `sqrt(2*pi)/3.33`, whereas I think you meant to have all of that in the denominator. So you need parentheses: `1/(3.33 * sqrt(2*pi))`, as in @eric_g's answer.Sat, 15 Aug 2020 18:02:24 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53033#post-id-53033Answer by Emmanuel Charpentier for <p>This is what I want to do in Sage. It can be done very easily in Desmos. <a href="https://www.desmos.com/calculator/7ocj57rixb">https://www.desmos.com/calculator/7oc...</a></p>
<p>I am just trying to do this integral in Sage. When I do it the answer I get is</p>
<p>f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)</p>
<p>N(definite_integral(f(x), x, 6, 23))</p>
<p>5.35572539176154</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?answer=53020#post-id-53020This smells (sloppily reported) homework at ten yards, so a few *hints*.
- Sage grammar needs *explicit* operators:`(a)(b)` will *not* be interpreted as a*b...
- Do not use numerical approximations when you have exact values :
+ `N(pi)`and `N(e)` should advantageously replaced by `pi` and `e`
+ Your `3.33` reeeks of `3/10`
+ Re-read your homework statement and look for a more formal definition of your `9.486` constant.
- Be more precise "I get a big error" does *not* help the poor sod, still running *H sapiens sapiens L.* without mind-reading interface or divoinatory coprocessor, who's trying to divine ***what*** error you got, and what hint you may have extracted from it (if only you took the time to read it...).
HTH,Sat, 15 Aug 2020 02:10:56 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?answer=53020#post-id-53020Comment by Emmanuel Charpentier for <p>This smells (sloppily reported) homework at ten yards, so a few <em>hints</em>.</p>
<ul>
<li><p>Sage grammar needs <em>explicit</em> operators:<code>(a)(b)</code> will <em>not</em> be interpreted as a*b...</p></li>
<li><p>Do not use numerical approximations when you have exact values :</p>
<ul>
<li><p><code>N(pi)</code>and <code>N(e)</code> should advantageously replaced by <code>pi</code> and <code>e</code></p></li>
<li><p>Your <code>3.33</code> reeeks of <code>3/10</code></p></li>
<li><p>Re-read your homework statement and look for a more formal definition of your <code>9.486</code> constant.</p></li>
</ul></li>
<li><p>Be more precise "I get a big error" does <em>not</em> help the poor sod, still running <em>H sapiens sapiens L.</em> without mind-reading interface or divoinatory coprocessor, who's trying to divine <strong><em>what</em></strong> error you got, and what hint you may have extracted from it (if only you took the time to read it...).</p></li>
</ul>
<p>HTH,</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53043#post-id-53043Your original post (before edition by John Palmieri) contained syntactic errors in your expression (= meaningless expression for Sage) ; The error message should have hinted at this.
Not giving the error message is requiring the (volunteer, unpaid, unobligated) person answering you to *guess* not only the solution to your problem but also what the problem is in the first place, thus doubling the (uncompensated) workload. That's usually considered rude...
FWIW, this forum regularly receives "questions" that aref high-school or university homework. A wide consensus is to give *hints* rather than a solution, in order to keep the point...
FYI, after *guessing* what you wanted to type, Sage is perfectly capable to give you a correct answer, both analytically (= symbolically) and numericallySat, 15 Aug 2020 22:16:15 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53043#post-id-53043Comment by Alex89 for <p>This smells (sloppily reported) homework at ten yards, so a few <em>hints</em>.</p>
<ul>
<li><p>Sage grammar needs <em>explicit</em> operators:<code>(a)(b)</code> will <em>not</em> be interpreted as a*b...</p></li>
<li><p>Do not use numerical approximations when you have exact values :</p>
<ul>
<li><p><code>N(pi)</code>and <code>N(e)</code> should advantageously replaced by <code>pi</code> and <code>e</code></p></li>
<li><p>Your <code>3.33</code> reeeks of <code>3/10</code></p></li>
<li><p>Re-read your homework statement and look for a more formal definition of your <code>9.486</code> constant.</p></li>
</ul></li>
<li><p>Be more precise "I get a big error" does <em>not</em> help the poor sod, still running <em>H sapiens sapiens L.</em> without mind-reading interface or divoinatory coprocessor, who's trying to divine <strong><em>what</em></strong> error you got, and what hint you may have extracted from it (if only you took the time to read it...).</p></li>
</ul>
<p>HTH,</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53028#post-id-53028I don't understand why did you bother to respond if you have no idea why Sage does not compute a definite integral of a normal distribution. And no this is not a homework. I solved it in Desmos in 1 minute. I just wanted to learn how to do it in Sage since I wanted to learn how to use it better. I had no idea that you have to be an expert to even ask questions around here.Sat, 15 Aug 2020 11:13:34 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53028#post-id-53028Answer by eric_g for <p>This is what I want to do in Sage. It can be done very easily in Desmos. <a href="https://www.desmos.com/calculator/7ocj57rixb">https://www.desmos.com/calculator/7oc...</a></p>
<p>I am just trying to do this integral in Sage. When I do it the answer I get is</p>
<p>f(x) = (1/3.33sqrt(2pi))exp((-1/2)((x-9.486)/3.33)^2)</p>
<p>N(definite_integral(f(x), x, 6, 23))</p>
<p>5.35572539176154</p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?answer=53030#post-id-53030You should use `numerical_integral`:
sage: f(x) = 1/(3.33*sqrt(2*pi))*exp(-1/2*((x-9.486)/3.33)^2)
sage: numerical_integral(f, (6,23))
(0.8523901699416254, 9.463431926333425e-15)
The second number in the output is an estimate of the numerical error (type `numerical_intergal?` for more details, in particular for options to control the numerical error).
Sat, 15 Aug 2020 11:37:14 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?answer=53030#post-id-53030Comment by Alex89 for <p>You should use <code>numerical_integral</code>:</p>
<pre><code>sage: f(x) = 1/(3.33*sqrt(2*pi))*exp(-1/2*((x-9.486)/3.33)^2)
sage: numerical_integral(f, (6,23))
(0.8523901699416254, 9.463431926333425e-15)
</code></pre>
<p>The second number in the output is an estimate of the numerical error (type <code>numerical_intergal?</code> for more details, in particular for options to control the numerical error). </p>
https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53031#post-id-53031This is perfect. Thank you!Sat, 15 Aug 2020 12:22:34 +0200https://ask.sagemath.org/question/53018/error-when-trying-to-integrate/?comment=53031#post-id-53031