# 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/7oc...

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.35572539176154

edit retag close merge delete

Don't use "N": just use 2*pi and exp(...).

I 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.

Sort by » oldest newest most voted

You 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).

more

This 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,

more

I 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.

Your 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 numerically