Showing posts with label taylor series. Show all posts
Showing posts with label taylor series. Show all posts

Saturday, January 29, 2022

Binomial Expansion in Two Methods

Binomial Expansion in Two Methods


Expanding the Binomial by Two Methods


There are two ways to obtain the coefficients of expanding the binomial in the form (a ∙ x + b)^n:


1.  Binomial Theorem:


(a ∙ x + b)^n = Σ(comb(n, k) ∙ (a ∙ x)^k ∙ b^(n -k), k=0, n)

where comb(n,k) = n! ÷ (k! × (n - k)!)



2.  Maclaurin Series (Taylor series at point x=0):


f(x) = (a ∙ x + b)^n

f(x) =  f(0) + f'(0) ∙ x + f''(0)÷2! ∙ x^2 + f'''(0)÷3! ∙ x^3 + ... + f^n(0)÷n! ∙ x^n


Let's illustrate this through several examples.


Example 1:   (2∙x+3)^2


Binomial Theorem:

(2∙x+3)^2 

= comb(2,0)∙(2∙x)^2 + comb(2,1)∙(2∙x)∙3 + comb(2,2)∙3^2

= 4∙x^2 + 12∙x + 3


Maclaurin Series:

f(x) = (2∙x+3)^2,  f(0)=9

f'(x) = 4∙(2∙x+3), f'(0)=12

f''(x) = 8,  f''(0)=8

(2∙x+3)^2 = 9 + 12÷1! ∙ x + 8÷2! ∙ x^2 = 9 + 12∙x + 4∙x^2


Example 2:   (x + 5)^3


Binomial Theorem:

(x+5)^3

= comb(3,0)∙x^3 + comb(3,1)∙x^2∙5 + comb(3,2)∙x∙5^2 + comb(3,3)∙5^3

= x^3 + 15∙x^2 + 75∙x + 125


Maclaurin Series:

f(x) = (x+5)^3, f(0) = 125

f'(x) = 3∙(x+5)^2, f'(0) = 75

f''(x) = 6∙(x+5), f''(0) = 30

f'''(x) = 6, f'''(0) = 6

(x + 5)^3 = 125 + 75÷1! ∙ x + 30÷2! ∙x^2 + 6÷3! ∙ x^3 

= 125 + 75∙x + 15∙x^2 + x^3


Example 3:  A general binomial:  (a∙x+b)^2


Binomial Theorem:

(a∙x+b)^2

= comb(2,0)∙(a∙x)^2 + comb(2,1)∙(a∙x)∙b + comb(2,2)∙b^2

= a^2∙x^2 + 2∙a∙b∙x + b^2


Maclaurin Series:

f(x) =  (a∙x+b)^2, f(0) = b^2

f'(x) = 2∙(a∙x+b)∙a, f'(0) = 2∙a∙b

f''(x) = 2∙a^2, f''(0) = 2∙a^2

(a∙x+b)^2 = b^2 + (2∙a∙b)÷1! ∙x + (2∙a^2)÷2! ∙x^2 = b^2 + 2∙a∙b∙x + a^2∙x^2

 


Two ways of obtaining the expansion of the binomial.   


Eddie 


Monday, October 4, 2021

Simple Generating Functions

 Generating Functions 


Generating a Sequence Via a Function


A generating function, g(x), can be expressed as a power series polynomial.  The coefficients of such polynomials make up the generating sequence.


g(x) = Σ( c_k * x^k, k=0 to ∞) = c_0 + c_1 * x + c_2 * x^2 + c_3 * x^3 + ....


The generated sequence is {c_0, c_1, c_2, c_3, ... }.


A simple approach is find the Maclaurin Series (Taylor Series about the point 0) of g(x).


Example:


g(x) = 2 ÷ (1 - 3*x)


The Maclaurin Series of g(x) is:


2 + 6*x + 18*x^2 + 54*x^3 + 162*x^4 + 486*x^5 + ...


with the sequence of { 2, 6, 18, 54, 162, 486 ... }


Some Simple Generating Functions

1 ÷ (1 - x) = 1 + x + x^2 + x^3 + x^4 + ....

÷ (1 - x) = b + b + b^2 + b^3 + b^4 + ....

1 ÷ (1 - a*x) = 1 + a*x + a^2*x^2 + a^3*x^3 + a^4*x^4 + ....

1 ÷ (1 - x)^2 = 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + ....

1 ÷ (1 + x) = 1 - x + x^2 - x^3 + x^4 - x^5 + ....



(as pictures the size of 3" x 5" index cards:  let me know if you want more posts like this - Eddie)





All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, December 6, 2020

Calculus of the Sinc Function

Calculus of the Sinc Function


Introduction and Setup


The unnormalized Sinc function is defined as:


unsinc(x) = sin x / x


And the normalized Sinc function is defined as:


sinc(x) = sin( π x ) / ( π x )


Two things to assume about the sinc function:


1.  The function is not defined at x = 0, and


2.  The function uses radian angle measure.  


(x ≠ 0, and assume radians measure)



Let α be a real constant and define f(x) as:


f(x) = sin( α x ) / (α x)


When α = 1, f(x) becomes unsinc(x).  Likewise, when α = π, f(x) becomes sinc(x).  I am going to analyze this function f(x).


Limit


Limit of sin( α x ) / ( α x )


lim x → 0 ( sin( α x ) / ( α x ) ) → sin 0 / 0 → 0 / 0


This form of improper limit allows us to use L'Hôspital's Rule, which allows us to take the derivative of both the numerator function and denominator function:


lim x → 0 ( α * cos ( α x ) / α ) → lim x → 0 ( cos ( α x ) ) →  cos ( 0 ) → 1


Hence  lim x → 0 ( sin( α x ) / ( α x ) ) → 1


Derivative


Taking the derivative will call for use to use the quotient rule:


d/dx [n(x) / d(x)] = ( n '(x) * d(x) - n(x) * d '(x)) / (d^2(x))


Then:


d/dx [ sin( α x ) / ( α x ) ]:


n(x) = sin ( α x )

n'(x) = α * cos( α x )

d(x) = α * x 

d^2(x) = (α * x)^2

d'(x) = α



d/dx [ sin( α x ) / ( α x ) ]

= [ α * cos( α x ) * α * x - sin( α x ) * α ] / [ α^2 * x^2 ]

= [ α^2 * cos( α x ) * x - sin( α x ) * α ] / [ α^2 * x^2 ]

= [ α * cos( α x ) * x - sin( α x ) ] / [ α * x^2 ]

= cos( α x ) / x^2 - sin( α x ) / (α * x^2)


Integral


The integral of 


∫ sin( α x ) / ( α x ) dx


does not look like it can easily integrated.


Let's use the Taylor Series approach:


sin x = x - x^3 / 3! + x^5 / 5! - x^7 / 7! + x^9 / 9! + . . . 


sin( α x ) =  ( α x ) - ( α x )^3 / 3! + ( α x )^5 / 5! - ( α x )^7 / 7! + ( α x )^9 / 9! + ...


With x≠0


sin( α x ) / ( α x ) 

=  1 - ( α x )^2 / 3! + ( α x )^4 / 5! - ( α x )^6 / 7! + ( α x )^8 / 9! + ...

=  1 -  α^2 * x^2 / 3! + α^4 * x^4 / 5! - α^6 * x^6 / 7! + α^8 * x^8 / 9! + ...



Now integrate the series:


∫ sin( α x ) / ( α x ) dx

=  x - ( α^2 * x^3 ) / (3 * 3!) + ( α^4 * x^5 ) / (5 * 5!) - ( α^6 * x^7 ) / (7 * 7!) +  ( α^8 * x^9 ) / (9 * 9!) + ... + C

 =  x - ( α^2 * x^3 ) / 18 + ( α^4 * x^5 ) / 600 - ( α^6 * x^7 ) / 35280 +  ( α^8 * x^9 ) / 3265920 + ... + C


Eddie


All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Friday, June 3, 2016

The functions e^x, e^-x, e^(-x^2), erf(x) and Taylor Series

The functions e^x, e^-x, e^(-x^2), erf(x) and Taylor Series

Accurate digits are highlighted in green.  Calculations are used with a TI 84 Plus CE.

e^x = 1 + x + x^2/2! + x^3/3! + x^4/4 + … = Σ(x^n/n!, from n = 0 to ∞)

x =
e^x
10 terms
25 terms
50 terms
1
2.718281828
2.718281801
2.718281828
2.718281828
3
20.08553692
20.07966518
20.08553692
20.08553692
5
148.4131591
146.380601
148.4131591
148.4131591
9.9
19930.37044
11869.50538
19930.07221
19930.37044


e^(-x) = 1 – x + x^2/2! – x^3/3! + x^4/4 - … = Σ( (-x)^n/n!, from n = 0 to ∞)

x =
e^(-x)
10 terms
25 terms
50 terms
1
0.3678794412
0.3678794643
0.3678794412
0.3678794412
3
0.0497870684
0.0533258929
0.0497870684
0.0497870684
5
0.006737947
0.8640390763
0.0067379439
0.006737947
9.9
5.017468206E-5
1207.799663
-0.1392914019
5.017463241E-5

I think you know where I’m going.

e^(-x^2) = 1 – x^2 + x^4/2! – x^6/3! + x^8/4! = Σ( (-x)^(2*n)/n!, from n = 0 to ∞)

x =
e^(-x^2)
10 terms
25 terms
50 terms
1
0.3678794412
0.3678794643
0.3678794412
0.3678794412
3
1.234098041E-4
442.2750223
-0.0118646275
1.234194001E-4
5
1.38879439E-11
18613495.8
-2834107793
85689.40174
9.9
2.72143414E-43
2.04347238E13
-3.10254183E24
7.951057508E34

(Something really goes bonkers as x increases and n increases)

Error Function
erf(x) = 2/√π * ∫(e^(-t^2) dt, 0, x)
= 2/√π * (x – x^3/3 + x^5/(5*2!) – x^7/(7*3!) + x^9/(9*4!) - ...)
= 2/√π * Σ( (-x^(2n+1)/((2n+1)*n!) from n = 0 to ∞ )

x =
erf(x)
10 terms
25 terms
50 terms
1
0.8427007929
0.8427007941
0.8427007929
0.8427007929
3
0.9999779095
68.58627744
0.9992050426
0.9999779095
5
1
4853382.901
-3070260210.4
4724.331354
9.9
1
1.076461715E13
-6.7395908E23
*overflows during calculation*
(Result: 8.73442E33 from WolframAlpha)
(erf(x) is practically 1 for x > 3)

Note: 9.9^(2*50+1) ≈ 3.623E100


Thoughts:

*  Taylor series are great when x is near its center point.  In the all the cases above, the center point is x = 0. 

*  The more simple the expression, the better range of accuracy with less terms. 

*  Before you recommend a Taylor Series to approximate f(x), check the accuracy and the range.  A cautionary tale. 

Eddie


This blog is property of Edward Shore, 2016.

Wednesday, April 18, 2012

Calculus Revisited # 20: Taylor Series and Maclaurin Series

Welcome to Part 20 of 21: Taylor and Maclaurin Series.

The Taylor and Maclaurin series are representation of the function f(x) by using an infinite series. If we use a finite number of terms, the series can (I stress can), but a good approximation f(x).

A Taylor series of f(x) is centered on a focus point x = a. Generally, approximations are best when x is around a, and gets worse the further x gets from a.

Taylor Series:

About the point x = a:

f(x) = f(a) + f'(a) * (x - 1) + f''(a) * (x - a)^2 / 2! + f'''(a) * (x - a)^3 / 3! + ....

If the series is cut off at n terms, the final term of the Taylor series is:

f^(n+1)(t) / (n+1)! * (x - a)^(n+1). This is known as the error term.

Maclaurin Series:

The Taylor series with a = 0.

f(x) = f(0) + f'(0) * x + f''(0) * x^2/2! + f'''(0) *x^3/3! + ...

With error term f^(n+1)(0) / (n+1)! * x^(n+1)

Some famous series:

e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + .... + x^n/n! + ....

sin x = x - x^3/3! + x^5/5! - x^7/7! + .... + ( (-1)^n * x^(2n+1) ) / (2n+1)! + ....

cos x = 1 - x^2/2! + x^4/4! - x^6/6! + ... + ( (-1)^n * x^(2n) ) / (2n)! + ....

Problems

1. Find a Macluarin series for

f(x) = ln(x + 1) to four terms

f(x) = ln(x + 1)
f(0) = ln(0 + 1) = 0

f'(x) = 1/(x+1)
f'(0) = 1/1 = 1

f''(x) = -1/(x+1)^2
f''(0) = -1/(1^2) = -1

f'''(x) = 2/(x+1)^3
f'''(0) = 2/(1^3) = 2

Then:

ln(x + 1) = 0 + 1 * x + (-1) * x^2/2! + 2 * x^3/3! + ....
= x - x^2/2! + 2x^3/3! + ....

2. Find the Macluarin series for

f(x) = e^(-x^2) to three nonzero terms. Approximate its integral.

f(x) = e^(-x^2)
f(0) = 1

f'(x) = e^(-x^2) * (-2x)
f'(0) = 0

f''(x) = e^(-x^2) * (4x^2 - 2)
f''(0) = -2

f'''(x) = e^(-x^2) * (-8x^3 + 12x)
f'''(0) = 0

f''''(x) = e^(-x^2) * (16x^4 - 48x^2 + 12)
f''''(0) = 12

Then:

e^(-x^2) = 1 - 2 * x^2/2! + 12 * x^4/4! + ....
= 1 - x^2 + x^4/2 + ...

∫ e^(-x^2) dx = x -x^3/3 + x^5/10 + .... + C

3. Find the Taylor series for cos x at a = π/4 to three nonzero terms.

f(x) = cos x
f(π/4) = √2/2

f'(x) = - sin x
f'(π/4) = -√2/2

f''(x) = -cos x
f''(π/4) = -√2/2

Then:

cos x = √2/2 - √2/2 * (x - π/4) + √2/2 * (x - π/4)^2/2! + ....

That concludes our section on Taylor and Maclaurin series. The next and last entry will be our "catch all" entry.

Thank you as always,

Eddie

This blog is property of Edward Shore. © 2012

RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...