Showing posts with label numerical approximations. Show all posts
Showing posts with label numerical approximations. Show all posts

Wednesday, March 2, 2016

HP Prime and Casio fx-5800p Approximating the Factorial Function

HP Prime and Casio fx-5800p Approximating the Factorial Function

A quick way to estimate the factorial function, which is good for all real numbers (and complex numbers with the HP Prime) is determined by Gergő Nemes Ph. D (Mathematics, University of Edinburgh):

N! ≈ N^N * √(2*π*N) * e^(1/(12*N+2/(5*N+53/(42*N)))-N)

The error is the order of 1 + O(N^-8).   Like the Sterling approximation formula, this formula is a better approximation as N increases. 

Casio fx-5800p Program:  GERGO

“GERGO RSKEY.ORG”
“N”? → N
N^(N)*√(2πN)*e^(
1÷(12N+2÷(5N+53÷
(42N)))-N)

HP Prime:  GERGO

EXPORT GERGO(N)
BEGIN
// rskey.org 2016-03-02
RETURN N^N*√(2*N*π)*
e^(1/(12*N+2/(5*N+53/(42*N)))
-N);
END;

How accurate is it?

Here a test of some random values to compare accuracy.

Values

N
N! (Determined by Wolfram Alpha)
N! approximation
1.25
1.13300309631…
1.133039736
3.08
6.64025496878…
6.640255733
5
120
120.0000005
6.64
2460.94013688180…
2460.940138
8.27
72172.53628421024…
72172.53629
11.5
1.368433654655… x 10^8
136843365.5

Source:

“Sterling’s Approximation”  Wikipedia – Page February 26, 2016 https://en.wikipedia.org/wiki/Stirling%27s_approximation#cite_note-Nemes2010-10 Retrieved March 1, 2016


Toth, Viktor T.  “The Gamma Function”  R/S Programmable Calculators  http://www.rskey.org/CMS/the-library?id=11  Retrieved March 1, 2016

Wednesday, February 17, 2016

HP Prime: Hermite Interpolation – 2 Points Known

HP Prime:  Hermite Interpolation – 2 Points Known

Hermite Interpolation:  Many calculations of divided differences


 Introduction

The program HERMITE2 interpolates two data points to determine the value of an unknown function at a third point.  What is unique about Hermite Interpolation is that that not only the two data points are known, but the slopes (first derivatives) are also given.   Hermite Interpolation will require a lot of calculations, especially when more than two points are known.

The 2-Known Points Case

We have points (x0, y0, y’0) and (x1, y1, y’1) and we want to determine y for a given value of x.  The approximation of y is determined by divided differences.

For two points known: 

z0:  x0, y0




z01 = y’0


z1: x0, y0

z02 = (z12 – z01)/(x1 – x0)


z12 = (y1 – y0)/(x1 – x0)

z13 = (z13 – z02)/(x1 – x0)
z2: x1, y1

z13 = (z23 – z12)/(x1 – x0)


z23 = y’1


z3: x1, y1




And y = H3(x) = y0 + y’0 * (x – x0) + z02 * (x – x0)^2 + z13 * (x – x0)^2 * (x – x1)


The arguments of HERMITE2 are as follows:  x0, y0, y’0 (labeled dx0), x1, y1, y’1 (labeled dx1), x. 

HP Prime:  Program HERMITE2

EXPORT HERMITE2(x0,y0,dy0,x1,y1,dy1,x)
BEGIN
// Hermite Interpolation
// 2 points
// 2016-02-16
LOCAL z12,dx,z02,z13,z03,y;
dx:=x1-x0;
z12:=(y1-y0)/dx;
z02:=(z12-dy0)/dx;
z13:=(dy1-z12)/dx;
z03:=(z13-z02)/dx;
y:=y0+dy0*(x-x0)+
z02*(x-x0)^2+
z03*(x-x0)^2*(x-x1);
RETURN y;
END;

Example:

Given: x0 = 0, y0 = 0, y’0 = 1; x1 = 1, y1 = 1, y’1 = 0.78
For x = 0.5, result is y = 0.5275
For x = 0.78, result is y = 0.80944656

Source:

Faires, J. Douglas and Burden, Richard.  Numerical Methods – 3rd Edition  Thompson Brooks/Cole: Pacific Grove, CA  2003


Until next time everyone, happy computing!     Eddie

This blog is property of Edward Shore.  2016


Monday, July 23, 2012

Numerical Approximations and Debunking the Claim that π has an exact value


Greetings,

I apologize for not blogging sooner (getting over a nasty sore throat/cold). I am still working on the application series, planning to get that started on or before August 1, 2010.

Numerical Approximations

In the meantime, I am also reading about a series of numerical analysis by Namir Shammas. Please click here to go to his web page. . I am really fascinated about his paper on integration methods and polynomials he uses to better fit data.

There is also a paper on inverse distribution which can come in handy for those in statistics and probability. For example, the inverse normal distribution lets you find the z-point given the α, the level of significance. So, if the given area under the normal curve is .95, α = .05.

Is There an Exact Value for π? One Man Thinks So (He Isn't Correct)

There is this mathematician from India who claimed to have found an exact value for π, which the claimed value was well off from the true value of 3.14159265359... (off by at least .005). The way he found his value for π was by a Sieve method, which was a very confusing method involving dissecting an circle inscribed in a square, and balancing areas of circular sectors inside and outside the inscribed circle. Problem was he made an assumed value for π to conclude some convenient number. I did not get into his other two methods.

Here is the article where the errors are posted, published by Acme Science, a blog authored by Samuel Hansen (Twitter: @Samuel_Hansen): please click here.

I hope your days are well and without sickness. You can follow me on Twitter: @edward_shore. Until next time,

Eddie



DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...