Processing math: 100%
Ask Your Question
0

Problem recreating example of normal distribution from TI-Nspire [closed]

asked 8 years ago

Ross1856 gravatar image

I have to recreate this formula for calculating normal distribution in Sage:

http ://ntaj.dreamhosters.com/ti.jpg

The picture is from TI-Nspire CAS.

What I'm doing is:

sage: f=1/(0.1sqrt(2pi)) * e^((-1/2)*((x-4)/0.1))^2

sage: float(integral(f, 3.9, 4.1))

0.8696735925295498

I can't get the expected result 0.682689 that Nspire gives. Can anyone see why?

Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by Ross1856
close date 2017-04-28 11:24:30.118994

2 Answers

Sort by » oldest newest most voted
0

answered 8 years ago

eric_g gravatar image

You did not get the expected result because the last ^2 is ill placed; it should be inside the parentheses:

sage: f = 1/(0.1*sqrt(2*pi)) * e^((-1/2)*((x-4)/0.1)^2)

Then

sage: numerical_integral(f, 3.9, 4.1)
(0.6826894921370853, 7.579375928402468e-15)

(the second number is an evaluation of the numerical error).

Preview: (hide)
link
0

answered 8 years ago

dan_fulea gravatar image

Pari/gp delivers:

? s = 0.1;

? intnum( x=3.9, 4.1, exp( -(x-4)^2/2/s^2 ) / sqrt(2*Pi*s^2) )                                                                
%2 = 0.6826894921370858971704650911

We can do the same in sage, i.e. call gp:

sage: gp( "intnum( x=3.9, 4.1, exp( -(x-4)^2/2/%s^2 ) / sqrt(2*Pi)/%s)" % ( 0.1, 0.1 ) )
0.6826894921370858971704650911

Or call the numerical integral from sage:

sage: integral_numerical( lambda x :    exp( -(x-4)^2/2/0.1^2 ) / sqrt(2*pi)/0.1, 3.9, 4.1 )
(0.6826894921370853, 7.579375928402468e-15)

which computes the approximative value 0.6826894921370853 with an error less than 7,61015, as given in the second argument.

Preview: (hide)
link

Comments

I'll have to read up on that. Thank you for the reference.

Ross1856 gravatar imageRoss1856 ( 8 years ago )

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 303 times

Last updated: Apr 27 '17