Trident Help

RPN Scientific 15 manual · Chapter 9 of 12

SOLVE and integration

Find a root of any function you write as a program with SOLVE, and integrate a function between two limits with ∫xy.

9.1Write the function as a program#

SOLVE and ∫xy both work on a function you have written as a small program. The program starts with a label, takes x from X, leaves f(x) in X, and ends with RTN. When SOLVE or ∫xy runs your program, x is copied into all four stack registers, so you can use the stack freely.

To write x² − 2 under label 0: press gP/RR/S (program mode on), then fLBLSST 0 (the label), then gx²√x (x²), 2, −, and gRTNGSB (RTN). Press gP/RR/S again to leave program mode. See Programming for all the details.

9.2Find a root with SOLVE#

f(x)=0f(x)=0
SOLVE looks for a value x where your program returns zero.
  1. guess in Y
  2. ENTER
  3. guess in X
  4. fSOLVE÷
  5. label
  6. root in X
Using SOLVE.

A root is a value of x where f(x) = 0. Key in two guesses (the first in Y, the second in X), then press fSOLVE÷ (SOLVE) and the label. The calculator searches from your guesses. It works best when the guesses are on either side of the root, but it can find a root from two guesses on the same side too.

When it finishes, X holds the root. Y holds the previous estimate (the same value when it has converged). Z holds f at the root, which should be zero or very close.

Example 9.1

The square root of 2

  1. Enter x² − 2 under label 0. Key in the guesses 1 and 2, then press f, SOLVE, 0.

    gP/RR/SfLBLSST0gx²√x2−gRTNGSBgP/RR/S1ENTER2fSOLVE÷0
Result of the example "The square root of 2" The display shows:  0.0000 /  0.0000 /  1.4142 /  1.4142.
You should seeThe root is 1.4142.
Example 9.2

A negative root

  1. Same program. Use negative guesses −3 and −1.

    gP/RR/SfLBLSST0gx²√x2−gRTNGSBgP/RR/S3CHSENTER1CHSfSOLVE÷0
Result of the example "A negative root" The display shows:  0.0000 /  0.0000 / -1.4142 / -1.4142.
You should see-1.4142
Example 9.3

See more digits

  1. Same program, then set FIX 9 and solve again.

    gP/RR/SfLBLSST0gx²√x2−gRTNGSBgP/RR/S1ENTER2fSOLVE÷0fFIX79
Result of the example "See more digits" The display shows:  0.000000000 /  0.000000000 /  1.414213562 /  1.414213562.
You should see1.414213562
After SOLVE: X holds the root 1.4142 and Z holds f(root), which is zero. The display shows:  0.0000 /  0.0000 /  1.4142 /  1.4142.
After SOLVE: X holds the root 1.4142 and Z holds f(root), which is zero.

9.3Solve an equation such as cos x = x#

To solve a(x)=b(x)a(x)=b(x), write a program that returns a(x)−b(x)a(x)-b(x). The root of that program is the solution. For cos x = x (angles in radians), take COS of x, bring x back with LSTx, and subtract.

Example 9.4

Solve cos x = x

  1. Switch to radians. Label 3 takes COS of x, brings x back with g, LSTx, and subtracts. Run it with guesses 0 and 1.

    gRAD8gP/RR/SfLBLSST3COSgLSTxENTER−gRTNGSBgP/RR/S0ENTER1fSOLVE÷3
Result of the example "Solve cos x = x" The display shows:  0.0000 / -1.0000  -13 /  0.7391 /  0.7391.
You should seeThe solution is x = 0.7391 radians.

In that program the second line g LSTx brings back the x that COS used, so the program returns cos x − x.

Example 9.5

Solve x³ − x − 1 = 0

  1. Label 4 returns x³ − x − 1. While the program runs, x is in X and Y, so the program takes x to the power 3 with swap, 3, yˣ, subtracts x, then subtracts 1. Run with guesses 1 and 2.

    gP/RR/SfLBLSST43yˣx⇄y−1−gRTNGSBgP/RR/S1ENTER2fSOLVE÷4
Result of the example "Solve x³ − x − 1 = 0" The display shows:  0.0000 /  1.0000  -12 /  1.3247 /  1.3247.
You should see1.3247

9.4Use a stored number inside the function#

The function program can recall registers, so one program can solve many problems. Store the changing part in a register and read it inside the program.

Example 9.6

Square root of a stored number

  1. Store 10 in R1. Label 5: x², RCL 1, −. Guesses 3 and 4. Press f, SOLVE, 5.

    10STO1gP/RR/SfLBLSST5gx²√xRCL1−gRTNGSBgP/RR/S3ENTER4fSOLVE÷5
Result of the example "Square root of a stored number" The display shows:  0.0000 /  0.0000 /  3.1623 /  3.1623.
You should seeThe root of x² − 10 is 3.1623.

9.5When SOLVE cannot find a root#

If the function never reaches zero near your guesses, you see Error 8. If the label is missing, you see Error 4. Try different guesses, or check the program by running it by hand.

Example 9.7

A function with no root

  1. Label 1: x² + 1 never reaches zero. Press f, SOLVE, 1 with guesses 1 and 2.

    gP/RR/SfLBLSST1gx²√x1+gRTNGSBgP/RR/S1ENTER2fSOLVE÷1
Result of the example "A function with no root" The display shows:   Error 8 /  0.0000 /  1.0008 / -0.0275 / -0.0275.
You should seeError 8

When SOLVE runs inside a program and finds no root, the next program line is skipped, so you can branch on the failure. The stack is left as it is. Do not start SOLVE from inside a program that SOLVE itself is running (Error 7).

9.6Integrate with ∫xy#

∫abf(x) dx\int_{a}^{b} f(x)\,dx
The area under f(x) from the lower limit a (in Y) to the upper limit b (in X).
Stack before and after ∫xy on label 1 (limits 0 and 1).

Key in the lower limit, ENTER, the upper limit, then press f∫xy× (∫xy) and the label. The area under f(x) between the limits comes back in X. Y holds an estimate of the error. Z holds the upper limit and T the lower limit.

The accuracy follows the display: more decimals in FIX (or SCI, ENG) mean a more careful calculation, which takes longer. Swapping the limits changes the sign of the answer.

Example 9.8

Integral of x² from 0 to 1

  1. Label 1: x² (g x², RTN). Key in 0, ENTER, 1 and press f, ∫xy, 1.

    gP/RR/SfLBLSST1gx²√xgRTNGSBgP/RR/S0ENTER1f∫xy×1
Result of the example "Integral of x² from 0 to 1" The display shows:  0.0000 /  1.0000 /  9.9920  -16 /  0.3333.
You should seeThe exact answer is 1/3, shown as 0.3333.
Example 9.9

Integral of 1/x from 1 to 2

  1. Label 3: 1/x. Limits 1 and 2.

    gP/RR/SfLBLSST31/xgRTNGSBgP/RR/S1ENTER2f∫xy×3
Result of the example "Integral of 1/x from 1 to 2" The display shows:  1.0000 /  2.0000 /  1.9933  -11 /  0.6931.
You should seeln 2 = 0.6931.
Example 9.10

Integral of sin x from 0 to π

  1. Radians. Label 2: SIN. Limits 0 and π.

    gRAD8gP/RR/SfLBLSST2SINgRTNGSBgP/RR/S0ENTERgπEEXf∫xy×2
Result of the example "Integral of sin x from 0 to π" The display shows:  0.0000 /  3.1416 /  1.9447  -12 /  2.0000.
You should see2.0000
Example 9.11

Reversed limits

  1. Same x² program with the limits the other way round: 1, ENTER, 0.

    gP/RR/SfLBLSST1gx²√xgRTNGSBgP/RR/S1ENTER0f∫xy×1
Result of the example "Reversed limits" The display shows:  1.0000 /  0.0000 /  9.9920  -16 / -0.3333.
You should see-0.3333
Example 9.12

More digits: integral of eˣ from 0 to 1

  1. FIX 9, label 4: eˣ. Limits 0 and 1.

    gP/RR/SfLBLSST4eˣgRTNGSBgP/RR/SfFIX790ENTER1f∫xy×4
Result of the example "More digits: integral of eˣ from 0 to 1" The display shows:  0.000000000 /  1.000000000 /  4.396483-14 /  1.718281828.
You should seee − 1 = 1.718281828.

See also Integrate on an RPN calculatorSolve an equation with your own programSolve an equation numerically

HP-15C is a trademark of HP Inc.. Trident Calculator is an independent product by South View Studios and is not affiliated with, sponsored by or endorsed by HP. The name is used only to describe the kind of calculator this model resembles; Trident's names, keys, display, fonts and software are its own clean-room design.