Saturday, February 6, 2016

TI 84 Plus: Numerical Second Derivative of Two Variables and OS 5.1 Update

TI 84 Plus:  Numerical Second Derivative of Two Variables and OS 5.1 Update

TI 84 Plus OS 5.1 Update

Texas Instruments released an update for the TI-84 Plus CE calculator 5.1. The link to download this update is:


I recommend that you save your programs and downloaded apps because installation will erase unarchived memory. 
 6
TI-84 Plus: Numeric Second Derivatives of Two Variables




    
The program DBLDERIV approximates the double second order partial derivatives of the two variable function f(x,y).  The program returns three results:

d^2/dx^2, stored in variable C.
d^2/dy^2, stored in variable D.
d^2/dxdy, stored in variable E.  For continuous functions, d^2/dxdy = d^2/dydx, and the program assumes that this is the case.

Formulas Used

For the function f(x,y) given Δx and Δy: 

Let H = Δx and K = Δy.  Note that H and K do not have to be equal values. H and K are typically small (such as 0.0001 to 0.01). 

Then:

d^2/dx^2 = 1/H^2 * ( f(x+H,y) – 2 * f(x,y) + f(x-H,y) )
d^2/dy^2 = 1/K^2 * ( f(x,y+K) – 2 * f(x,y) + f(x,y-K) )
d^2/dxdy = 1/(4*H*K) * ( f(x+H,y+K) – f(x+H,y-K) – f(x-H,y+K) + f(x-H,y-K) )

When prompted for f(x,y), enter the equation in quotes.  For example, enter f(x,y) = x – y^2 as “X-Y^2”.

Program DBLDERIV

Disp "DOUBLE PARTIAL"
Disp "DERIVATIVES"
Input "F(X,Y)=",Y₁
Input "X0=",A
Input "Y0=",B
Input "ΔX=",H
Input "ΔY=",K
A+H→X:B→Y:Y₁→C
A→X:C-2Y₁→C
A-H→X:(C+Y₁)/H²→C
A→X:B+K→Y:Y₁→D
B→Y:D-2Y₁→D
B-K→Y:(D+Y₁)/K²→D
A+H→X:B+K→Y:Y₁→E
B-K→Y:E-Y₁→E
A-H→X:B+K→Y:E-Y₁→E
B-K→Y:(E+Y₁)/(4HK)→E
Disp "C: D/DX²=",C
Disp "D: D/DY²=",D
Disp "E: D/DXDY=",E

Note: 
Pressing [ VARS ], 1, 8 types the ΔX character.
Pressing [ VARS ], 1, 9 types the ΔY character.

Examples

Remember that this program gives approximate values!

Example 1:  f(x,y) = sin(x*y), Radians Mode, x0 = π/2, y0 = π, H = K = 0.001

Results:
d^2/dx^2 = C = 9.62648815    (actual is about 9.62649603)
d^2/dy^2 = D = 2.40662356    (actual is about 2.406624007)
d^2/dxdy = E = 5.033820798   (actual is about 5.03382056)

Example 2:  f(x,y) = x^2*y^2 – x^3,  x0 = 1, y0 = 2, H = K = 0.001

Results:
d^2/dx^2 = C = 2
d^2/dy^2 = D = 2
d^2/dxdy = E = 8
In this case, we get the exact answers. 

Example 3:  f(x,y) = y^2*e^x, x0 = 0.1, y0 = 1.1, H = K = 0.001

Results:
d^2/dx^2 = C = 1.337257  (actual is about 1.337256811)
d^2/dy^2 = D = 2.203418  (actual is about 2.210341836)
d^2/dxdy = E = 2.4313764  (actual is about 2.43137602)

Source:

“Lecture 27: Numerical Differentiation”  This page is from the textbook:  Young, Todd & Mohelnkamp, Martin  “Introduction to Numerical Methods and Matlab Programming for Engineers”  Ohio University Math 3600 Course.   Retrieved January 30, 2016.  Link: https://www.math.ohiou.edu/courses/math3600/lecture27.pdf


Happy computing!

Eddie


 This blog is property of Edward Shore. 2016 


Thursday, February 4, 2016

TI-84 Plus: Simpson’s Rule for f(x,y)

TI-84 Plus: Simpson’s Rule for f(x,y)



If you are familiar with calculus and numerical methods, chances are that you are familiar with Simpson’s Rule.  Normally, Simpson’s Rule applies to functions of one variable, say f(x).  Today, we will apply the Simpson’s Rule to functions of two variables like f(x,y).

Start with the function f(x,y) and your integration limits A, B, C, and D.

Then determine Δx and Δy (labeled E and F in the programs below) by:

Δx = (B – A)/(N – 1)
Δy = (D – C)/(N – 1)

Where N is the number of partitions.  Unlike the Simpson’s Rule for one variable, in this case N must be odd.  Generally, the higher N is, the more accurate the approximation is, with the expense of additional computational time.

Next, build a matrix, let’s say [ I ].   This is your Simpson’s Matrix.  The Simpson’s Matrix is built by the expression

[ I ] = [1, 4, 2, 4, 2, 4, 2, 4, 2, …, 4, 1]^T * [1, 4, 2, 4, 2, 4, 2, 4, 2, …, 4, 1]

The length of the vector used to determine [ I ] depends on N.  A way to build it by the routine:

Store 1 into the element 1 of [ I ]  (first element)
Store 1 into the element N of [ I ]  (last element)
For J from 2 to N – 1
If J is divisible by 2, then store 4 in the jth element of [ I ],
Else store 2 in the jth element of [ I ]

For N = 5, the vector would be built is [1, 4, 2, 4, 1]

And

[ I ] = [1,4,2,4,1]^T * [1,4,2,4,1] =

[[1, 4, 2, 4, 1]
[4, 16, 8, 16, 4]
[2, 8, 4, 8, 2]
[4, 16, 8, 16, 4]
[1, 4, 2, 4, 1]]

Build another matrix [ J ].  The elements are determined by the following formulas:

For row j and column k, the element is f(A + Δx*(j – 1),  C + Δy*(k – 1))

Once finished, multiply every element of [ I ] by [ J ].  This is NOT matrix multiplication.   Then sum all of the elements of the results.  In essence:

S = ∑ (j = 1 to N) ∑ (k = 1 to N)   [I](j,k)* [J](j,k)

Determine the final integral approximation as:

Δx * Δy * 1/9 * S


The Programs

The following are three programs, one that set N = 5, N = 9, and the last one lets the user set a value for N.

Programs:

DBLSIMP:  N = 5

Disp "2D SIMPSONS"
Disp "INTEGRAL"
[[1,4,2,4,1][4,16,8,16,4][2,8,4,8,2][4,16,8,16,4][1,4,2,4,1]]→[I]
Input "F(X,Y)=",Y₁
Disp "X"
Prompt A,B
Disp "Y"
Prompt C,D
.25(B-A)→E
.25(D-C)→F
{5,5}→dim([J])
0→I
For(J,1,5)
For(K,1,5)
A+E(K-1)→X
C+F(J-1)→Y
Y₁→[J](J,K)
I+Y₁*[I](J,K)→I
End
End
I*E*F/9→I
Disp "INTEGRAL=",I



DBLS9:  N = 9 Version

Disp "2D SIMPSONS"
Disp "INTEGRAL"
[[1,4,2,4,2,4,2,4,1][4,16,8,16,8,16,8,16,4][2,8,4,8,4,8,4,8,2][4,16,8,16,8,16,8,16,4][2,8,4,8,4,8,4,8,2][4,16,8,16,8,16,8,16,4][2,8,4,8,4,8,4,8,2][4,16,8,16,8,16,8,16,4][1,4,2,4,2,4,2,4,1]]→[I]
Input "F(X,Y)=",Y₁
Disp "X"
Prompt A,B
Disp "Y"
Prompt C,D
(B-A)/8→E
(D-C)/8→F
{9,9}→dim([J])
0→I
For(J,1,9)
For(K,1,9)
A+E(K-1)→X
C+F(J-1)→Y
Y₁→[J](J,K)
I+Y₁*[I](J,K)→I
End
End
I*E*F/9→I
Disp "INTEGRAL=",I

DBLSMP: N can be set

Disp "2D SIMPSONS"
Disp "INTEGRAL"
Input "F(X,Y)=",Y₁
Disp "X"
Prompt A,B
Disp "Y"
Prompt C,D


Input "N (ODD)=",N
{1,N}→dim([I])
1→[I](1,1)
1→[I](1,N)
For(J,2,N-1)
If fPart(J/2)=0
Then
4→[I](1,J)
Else
2→[I](1,J)
End
End
[I]^T*[I]→[I]

(B-A)/(N-1)→E
(D-C)/(N-1)→F

{N,N}→dim([J])
0→I
For(J,1,N)
For(K,1,N)
A+E(K-1)→X
C+F(J-1)→Y
Y₁→[J](J,K)
I+Y₁*[I](J,K)→I
End
End
I*E*F/9→I
Disp "INTEGRAL=",I


One thing to note, when you are prompted enter your function, do not forget to use quotes.  Example, for x^2*y, enter “X^2*Y”. 

Caution:  Simpson’s Rule is an approximation, 100% accuracy is not guaranteed.

Of the three I recommend DBLSMP so you have control over N. 

Examples and Results

∫ ∫ x^2*y^3 dx dy, A = 0, B = 2, C = 1, D = 5
Result is 416 for both N = 5 and N = 9, agrees with the actual answer

∫ ∫ x^2 + y dx dy, A = 0, B = 2, C = 1, D = 1
Result is 5.666666667 for both N = 5 and N = 9, agrees with the actual answer

∫ ∫ sin(x*y) dx dy, A = 0, B = π, C = 0, D = 0.5
N = 5, result is 0.5568449485
N = 9, result is 0.5568006343
Actual answer is about 0.556797718751

To illustrate that Simpson’s Rule may not work out the best when N is low:
 ∫ x * e^(-y) dx dy,  A = 0, B =5, C = -2, D = 2
N = 5, result is 91.12098525
N = 9, result is 90.70208034
Actual answer is about 90.6715102

Source:
Cooper, Ian.  “Doing Physics With Matlab:  Mathematical Routines”  School of Physics, University of Sydney
Retrieved January 30, 2016

Until next time,
Eddie


This blog is property of Edward Shore.  2016

Monday, February 1, 2016

Video: Decimal/Hexadecimal Conversions

Happy February!

New Video:  Decimal/Hexadecimal Conversions

https://www.youtube.com/watch?v=2b5-Vjcq450

Coming Up

I am going to working on several numerical calculus routines, hopefully I will be posting in the upcoming couple of weeks.  They will be in text (not videos).  

Eddie




Tuesday, January 26, 2016

Monday, January 25, 2016

Video: Combinations vs Permutations

This short video explains the difference between combinations and permutations.

Link:  https://www.youtube.com/watch?v=Pj3sowlVbec



Eddie

Change of Plans

Apparently, someone on YouTube, maybe the company itself, doesn't like algebra. Who knew talking about the F.O.I.L. method was so offensive? I am appealing the decision.

For the time being, I will probably cease making videos until this matter is resolved (I expect it to be in my favor, but who knows). 

Eddie


Update: YouTube restored my FOIL video and I am back in good standing.  Happy dance!  Eddie

Sunday, January 24, 2016

Math Videos and Update

Sample Slide

Over the next few weeks I am going to working several short math videos that I will post on YouTube.  When each video is completed, I will leave a link to that video on this blog.  

The videos are going to be pretty short covering various topics in mathematics.  

I hope you enjoyed the HP 15C programs posted over the last two weeks.  I plan to continue to post programs for various calculators this year. 


 I thank you for the comments and reviews.  Talk to you next time, and be safe everyone,

Eddie

Thursday, January 14, 2016

HP 15C: Approximate Length of Sunlight During a Day



HP 15C:  Approximate Length of Sunlight During a Day

For the HP 35S version, please click here:


Source: Total Daily Amount of Solar Radiation - HP 67/97 Energy Conservation Pac, December 1978, Author: Hewlett Packard

Instructions:

Y Stack:  Enter the latitude (North as positive, South as negative).  Use the D.MMSS (degrees-minutes-seconds) format

X Stack:  The number of days after March 21.  A 365 day year is assumed, as well as assuming March 21 is the vernal equinox.

Run the program.

This is an approximation.

Program:

Step
Key
Key Code
001
LBL E
42, 21, 5
002
DEG
43, 7
003
.
48
004
9
9
005
8
8
006
5
5
007
6
6
008
*
20
009
SIN
23
010
2
2
011
3
3
012
.
48
013
4
4
014
5
5
015
*
20
016
X<>Y
34
017
>H
43, 2
018
TAN
25
019
X<>Y
34
020
TAN
25
021
CHS
16
022
*
20
023
COS^-1  (ACOS)
43, 32
024
>RAD
42, 3
025
2
2
026
4
4
027
*
20
028
π
43, 26
029
÷
10
030
>H.MS
42, 2
031
RTN
43, 32

Example:

Los Angeles, April 17.  Latitude of 34°03’ N, 27 days after March 21. 
Result:  approximately 12.5735 (12 hours, 57 minutes, 35 seconds)

Sydney, June 21.  Latitude of 33°51’31” S (enter as -33.5131), 92 days after March 21. 
Result:  approximately 9.4439 (9 hours, 44 minutes, 39 seconds)

Rome, September 1.  Latitude of 41°51’ N, 164 days after March 21.
Result:  approximately 12.5323 (12 hours, 53 minutes, 23 seconds)

This blog is property of Edward Shore.  2016


RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...