## 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 TLBL 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 TLBL 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 TLBL 5	x	-	-	-ENTER	x	x	-	-ENTER	x	x	x	-3	3	x	x	x+	x+3	x	x	x× 	x(x+3)	 x	x	x4	4	x(x+3)	 x	x-	x(x+3)-4 x	x	x1/x	1/...	x	x	x×	f(x)	x	x	xRTN`

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 TLBL 3		x		-		-		-ENTER		x		x		-		-ENTER		x		x		x		-3		3		x		x		xy^x		x^3		x		x		xx<>y		x		x^3		x		x2		2		x		x^3		x×		2x		x^3		x		x-		x^3-2x		x		x		x1		1		x^3-2x		x		x+		x^3-2x+1	x		x		x√		ø		x		x		xx<>y		x		ø		x		x÷		f(x)		x		x		xRTN`

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 6ENTERENTER3-× 4-√ ×RTN`

Result: 117.2455

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

`LBL 7ENTERENTER2-SINx<>yCOS÷× 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		CodeLBL A		42	21	11RCL 1			45	1STO 5			44	5RCL+ 0		45	40	0STO 3			44	3RCL 2			45	2STO 6			44	6GSB 0			32	0RCLx 0		45	20	0STO 7			44	7RCL 5			45	5RCL 0			45	03				3÷				10+				40STO 1			44	1RCL 6			45	6RCL 7			45 	73				3÷				10+				40STO 2			44	2GSB 0			32	0RCLx 0		45	44	0STO 8			44	8RCL 5			45	5RCL 0			45	02				2x				203				3÷				10+				40STO 1			44	1RCL 6			45	6RCL 8			45	82				2x				203				3÷				10+				40STO 2			44	2GSB 0			32	0RCLx 0		45	20	0STO 9			44	9RCL 3			45	3R/S				31RCL 6			45	6RCL 7			45	74				4÷				10+				40RCL 9			45	93				3x				204				4÷				10+				40STO 4			44	4RTN			43	32`

Example 1

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

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

Program for equation:

` LBL 0RADRCL 1x^2RCL 1RCLx 2SIN+RTNResults:x	y1.0000	1.00001.0100	1.01861.0200	1.03751.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 0RCL 13y^xRCLx 2RCL- 2RTNResults:x	y1.0000	1.00001.0100	1.00021.0200	1.00061.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 Prime CAS: Riemann-Louiville Integral vs Taking the Indefinite Integral Twice

HP Prime CAS: Riemann-Louiville Integral vs Taking the Indefinite Integral Twice Introduction The Riemann-Louiville Integral take...