Monday, January 2, 2012

Setting up Equations for Integration/Solve - HP 15C

Setting up equations for the integration and solve functions for the HP 15C. Since the release of the HP 15C Limited Edition, the processing speed has increased.

The most important thing to remember is that the equation starts with "x" on the x-register of the stack.

With integration, "x" is the variable to be integrated.

With the solve function, "x" is the variable to be solved for.

Depending on the equation, in general, you will need to duplicate "x" with [ENTER] as many times as "x" appears in the equation. Algebraic manipulation of the equation can be helpful. A technique known as Horner's Method can be used for polynomials. It also helps to handle the innermost expressions first, working outside.

I often straw a stack diagram:

ST X, ST Y, ST Z, ST T

Several things to remember:

Most two-argument functions (arithmetic, power, combination, permutation, etc):

ST T retains what was in ST T
ST Z copies the contents of ST T
ST Y the contents of ST Z moves here
ST X result of the function

Pressing ENTER, recalling from a memory register, or entering π

ST T the contents of ST Z moves here
ST Z the contents of ST Y moves here
ST Y the contents of ST X moves here
ST X the number just entered or recalled

Horner's Method

Let the polynomial p(x) = a_n * x^n + a_n-1 * x^(n-1) + ... + a1 * x + a0

Applying Horner's Method to p(x):

( ... (a_n * x + a_n-1) * x + a_n-2) * x + a_n-3) ... + a1 ) * x + a0

Functions

Integration: [ f ] [ x ] label

Solve: [ f ] [ ÷ ] label

This blog provides examples of integration, but ideas can be taken from the examples for use in solving equations.

Examples are in the format of:

b
∫ f(x) dx
a

All results shown here are rounded to 4 decimal places (FIX 4).

Example 1:

5
∫ x^2 * cos x dx
1

KEY ST X ST Y ST Z ST T
LBL 1 x - - -
ENTER x x - -
COS cos(x) x - -
x<>y x cos(x) - -
x^2 x^2 cos(x) - -
× f(x) - - -

Result: -19.4578

Example 2:

π
∫ x sin((π * x)/4) dx
0

KEY ST X ST Y ST Z ST T
LBL 2 x - - -
ENTER x x - -
π π x x -
× π*x x - -
4 4 π*x x -
÷ (π*x)/4 x - -
SIN sin(π*x/4) x - -
× f(x) - - -
RTN

Result: 4.1369

Example 3

3.5
∫ x / (x^2 + 3x - 4 ) dx =
3

3.5
∫ x / ((x + 3) *x - 4) dx
3

KEY ST X ST Y ST Z ST T
LBL 5 x - - -
ENTER x x - -
ENTER x x x -
3 3 x x x
+ x+3 x x x
× x(x+3) x x x
4 4 x(x+3) x x
- x(x+3)-4 x x x
1/x 1/... x x x
× f(x) x x x
RTN

Result: 0.0998

Example 4:

3
∫ √(x^3 - 2x + 1)/x dx
1

Let ø = √(x^3 -2x+1)

KEY ST X ST Y ST Z ST T
LBL 3 x - - -
ENTER x x - -
ENTER x x x -
3 3 x x x
y^x x^3 x x x
x<>y x x^3 x x
2 2 x x^3 x
× 2x x^3 x x
- x^3-2x x x x
1 1 x^3-2x x x
+ x^3-2x+1 x x x
√ ø x x x
x<>y x ø x x
÷ f(x) x x x
RTN

Result: 2.0912

Here are a few more examples of integrals. Try and draw the stack diagram for each step.

Example 5:

8.5
∫ x * √(x^2 - 3*x - 4) dx =
4.5

8.5
∫ x * √((x - 3) * x - 4) dx
4.5

LBL 6
ENTER
ENTER
3
-
×
4
-

×
RTN

Result: 117.2455

Example 6:
π/4
∫ x * (( sin(x-2) )/(cos x)) dx
0

LBL 7
ENTER
ENTER
2
-
SIN
x<>y
COS
÷
×
RTN

Result: -0.3578

I hope you find this blog helpful. Until next time, Eddie

This blog is property of Edward Shore. © 2012

3rd Order Runge-Kutta - HP 15C

This program uses a 3rd Order Runge-Kutta method to assist in solving a first order-differential equation.

Given the initial condition (x0, y0) to the differential equation:

dy/dx = f(x, y)

Find the value of y1 where h is a given step size (preferably small). The value of y1 is given by the following equations:

y1 = y0 + k1/4 + (3 * k3)/4

Where:
k1 = h * f(x0, y0)
k2 = h * f(x0 + h/3, y0 + k1/3)
k3 = h * f(x0 + (2 * h)/3, y0 + (2 * k2)/3)

Error estimated on the order of h^4

Source: Smith, Jon M. Scientific Analysis on the Pocket Calculator. John Wiley & Sons, Inc.: New York 1975 pg 174

Memory Registers Used

R0 = h
R1 = x
R2 = y
R3 = x1 (result)
R4 = y1 (result)
R5 = x0 (copied from R1)
R6 = y0 (copied from R2)
R7 = k1
R8 = k2
R9 = k3

Labels Used

Label A = Main Program
Label 0 = Program where equation is maintained

Instructions

1. Store h, x0, and y0 in memory registers R0, R1, and R2 respectively.
2. Enter or edit the equation in program mode using Label 0. Use RCL 1 for x and RCL 2 for y.
3. Run Program A. The first answer is x1. Press [R/S] for y1.
4. To find (x2, y2), store x1 in R1 and y1 in R2 and run Program A again. You can do this by pressing [STO] [ 2 ] [x<>y] [STO] [ 1 ] [ f ] [ √ ] (A) immediately following program execution.

There are 59 program steps in the main program.

Key Code
LBL A 42 21 11
RCL 1 45 1
STO 5 44 5
RCL+ 0 45 40 0
STO 3 44 3
RCL 2 45 2
STO 6 44 6
GSB 0 32 0
RCLx 0 45 20 0
STO 7 44 7
RCL 5 45 5
RCL 0 45 0
3 3
÷ 10
+ 40
STO 1 44 1
RCL 6 45 6
RCL 7 45 7
3 3
÷ 10
+ 40
STO 2 44 2
GSB 0 32 0
RCLx 0 45 44 0
STO 8 44 8
RCL 5 45 5
RCL 0 45 0
2 2
x 20
3 3
÷ 10
+ 40
STO 1 44 1
RCL 6 45 6
RCL 8 45 8
2 2
x 20
3 3
÷ 10
+ 40
STO 2 44 2
GSB 0 32 0
RCLx 0 45 20 0
STO 9 44 9
RCL 3 45 3
R/S 31
RCL 6 45 6
RCL 7 45 7
4 4
÷ 10
+ 40
RCL 9 45 9
3 3
x 20
4 4
÷ 10
+ 40
STO 4 44 4
RTN 43 32

Example 1

dy/dx = x^2 + sin(x * y)

Initial Conditions: (1, 1), let h = 0.01

Program for equation:

LBL 0
RCL 1
x^2
RCL 1
RCLx 2
SIN
+
RTN

Results:

x y
1.0000 1.0000
1.0100 1.0186
1.0200 1.0375
1.0300 1.0568

Example 2

dy/dx = x^3 * y - y

Initial Condition: (1,1); Step size h = 0.01

Program for the equation:

LBL 0
RCL 1
3
y^x
RCLx 2
RCL- 2
RTN

Results:

x y
1.0000 1.0000
1.0100 1.0002
1.0200 1.0006
1.0300 1.0014

This blog is property of Edward Shore. © 2012

Happy New Year!

Well 2012 is here! I hope everyone had a safe yet fun and celebratory New Years weekend. This is one of my favorite times of year.

Cheers!

Eddie

HP 17BII+: Prorated Mortgage Interest and Prorated Property Tax

HP 17BII+:   Prorated Mortgage Interest and Prorated Property Tax Both formulas presented today are from Michael C. Thomsett's book, Th...