Return to the Purplemath home page

 The Purplemath Forums
Helping students gain understanding
and self-confidence in algebra


powered by FreeFind

 

Return to the Lessons Index  | Do the Lessons in Order  |  Get "Purplemath on CD" for offline use  |  Print-friendly page



Numerical Approximation of Zeroes:
     A Program for the TI-84


If you're willing to take a little time, you can learn to write programs on your graphing calculator. Programming is a useful skill, and I highly recommend that you at least dabble, as it can be a great exercise in logic and planning.

To write a good program, one usually starts with "pseudo-code", which is a sketch of the general logic of the program. You decide what you want the program to do, and figure out the steps needed to accomplish the task. Another important thing to do, especially if you don't want to be dealing with the program "hanging" or crashing, is to try to anticipate problems. For approximating zeroes numerically, the user could, say, put in "bad" test points (points between which the function doesn't actually cross the axis, for instance). A good program would anticipate this and make allowances.


If you have a TI-84 calculator, you can download a program I wrote. If you do not have the ability to connect your TI-84 to your computer in order to upload the file directly, you can enter the program yourself. The coding is below. I think the program will also work on a TI-83. For other calculator models, you can imitate the logic, but the specific commands used by your model will differ from those displayed below.

In what follows, "STO>" means "store in", "ClrHome" means "clear screen", and "!=" means "not equal to", "Disp" means "display" (on the screen), "Lbl" is "label" (for directing "Goto" commands). The purple bracketed items are explanatory comments, and are not entered as part of the coding.


    [Clear the screen and introduce the program.]
    ClrHome
    Disp "THIS PROGRAM"
    Disp "WILL FIND THE"
    Disp "APPROXIMATE"
    Disp "VALUES OF ZEROES"
    Disp "BETWEEN BOUNDS"
    Disp "THAT YOU SUPPLY."
    Disp "    [ENTER]"
    Pause

    [The following label lets you re-run the program without re-running the introduction.]
    Lbl N4

    [Check that the function is entered. Accept the function, if it is not already stored elsewhere.]
    ClrHome
    Menu("IS F(X) IN Y1?","YES",N1,"NO",N2)

     

    ADVERTISEMENT

     

    [Go here if function needs to be entered; otherwise, go to N1.]
    Lbl N2

    [Explain required formatting for entry, and accept entry.]
    ClrHome
    Disp "ENTER F(X)"
    Disp "INSIDE QUOTE"
    Disp "MARKS."
    Disp " "
    Input "Y1 =",Y1

    [Go here if function is already stored elsewhere.]
    Lbl N1

    [Clear screen and request bounds on the zero.]
    ClrHome
    Disp "ENTER THE LOWER"
    Disp "(LEFT-HAND)"
    Disp "BOUND, A."
    Disp " "
    Input "A =",A
    ClrHome
    Disp "ENTER THE UPPER"
    Disp "(RIGHT-HAND)"
    Disp "BOUND, B."
    Disp " "
    Input "B =",B

    [Check that "lower bound" is actually lower than "upper bound". If not, go to re-entry menu at N5.]
    If A
    >B
    Then
    ClrHome
    Disp "THE LOWER BOUND"
    Disp "MUST BE LESS"
    Disp "THAN THE UPPER."
    Disp " "
    Disp "    [ENTER]"
    Pause
    ClrHome
    Goto N5
    End

    [Find y-values at given bounds.]
    A STO> X:Y1 STO> C
    B STO> X:Y1 STO> D

    [Check that y-values have opposite signs. If not, go to re-entry menu at N5.]
    If (((C<0) and (D<0)) or ((C>0) and (D>0)))
    Then
    ClrHome
    Disp "THERE IS NO SIGN"
    Disp "CHANGE BETWEEN"
    Disp "F(A) AND F(B)."
    Disp " "
    Disp "    [ENTER]"
    Pause
    ClrHome
    Goto N5
    Else
    ClrHome
    Goto N6
    End

    [If there is a problem with the entered bounds, offer to take new bounds, or to quit.]
    Lbl N5
    Menu("TRY NEW BOUNDS?","YES",N1,"NO (QUIT)",N9)

    [Come here once bounds are okay.]
    Lbl N6

    [Clear screen and see if either bound is itself a zero.]
    ClrHome
    A STO> X
    If Y1=0
    Then
    Disp "THE ZERO IS AT"
    Disp "A =",A
    Pause
    Goto N7
    End

    B STO> X

    If Y1=0
    Then
    Disp "THE ZERO IS AT"
    Disp "B =",B
    Pause
    Goto N7
    End

    [Come here to enter the desired accuracy.]
    ClrHome
    Lbl N3
      Copyright Elizabeth Stapel 2005-2011 All Rights Reserved

    [Clear the screen and request desired accuracy for the zero.]
    ClrHome
    Disp "ENTER DESIRED"
    Disp "NUMBER OF"
    Disp "DECIMAL PLACES"
    Disp "OF ACCURACY,"
    Disp "WITH N
    < 9."
    Disp " "
    Input "N =",N

    [Check the validity of the value for "number of decimal places". Allow for re-entering or quitting.]
    If ((N
    <0) or (N>9) or (int(N)N != 0))
    Then
    ClrHome
    Disp "THE NUMBER OF"
    Disp "DECIMAL PLACES"
    Disp "MUST BE SET TO"
    Disp "1, 2, 3, 4, 5,"
    Disp "6, 7, 8, OR 9."
    Disp "    [ENTER]"
    Pause
    ClrHome
    Menu("PICK NEW N?","YES",N3,"NO (QUIT)",N9)
    End

    {Store the initial bounds in variables for computation.]
    A STO> V
    B STO> W

    [Check to see if the bounds are already sufficiently close together.]
    If abs(WV)
    <10^(N)
    Then
    (W+Y)/2 STO> X
    Goto N8
    End

    [Clear the screen and put up a message to let the user know the program is running.]
    ClrHome
    Disp "WORKING..."

    [Do the following until either you find the exact zero or you find a sufficient approximation.]
    While ((abs(WV)>10^(N)) and (Y1 != 0))
    V STO> X:Y1 STO> C
    (W+V)/2 STO> X:Y1 STO> D

    [Check the signs on the y-values to pick which end the midpoint needs to replace.]
    If (((C<0) and (D<0)) or ((C>0) and (D>0)))
    Then
    X STO> V
    Else
    X STO> W
    End
    End

    [Come straight here if computations are unnecessary.]
    Lbl N8

    [Fix the display at the chosen number of decimal places. Clear the screen to display result.]
    Fix N
    ClrHome

    [Check to see if the zero is apparently exact or approximate. Return the appropriate message.]
    If Y1=0
    Then
    Disp "THE EXACT ZERO"
    Disp "IS AT X ="
    Disp X
    Else
    Disp "THE ZERO IS AT"
    Disp "ABOUT X ="
    Disp X
    End
    Pause

    [Come here when the program has successfully found a zero.]
    Lbl N7

    [Clear screen and offer options: quitting, or re-running various aspects of the program.]
    ClrHome
    Menu("WHAT NOW?","QUIT",N9,"NEW F(X)",N4,"NEW BOUNDS",N1,"NEW ACCURACY",N3)

    [Come here when the program is done, and do some clean-up before quitting.]
    Lbl N9

    [Return calculator's number display to "floating point". Clear the screen. End the program.]
    Float
    ClrHome
    Stop

Feel free to use or modify the above program. Just make sure you understand the logic of it.

Top  |  Return to Index

Cite this article as:

Stapel, Elizabeth. "Numerical Approximation of Zeroes: A Program for the TI-84."
    Purplemath. Available from 
http://www.purplemath.com/modules/numericp.htm.
    Accessed
 

 



Purplemath:
  Linking to this site
  Printing pages
  School licensing


Reviews of
Internet Sites:
   Free Help
   Practice
   Et Cetera

The "Homework
   Guidelines"

Study Skills Survey

Tutoring from Purplemath
Find a local math tutor


This lesson may be printed out for your personal use.

Content copyright protected by Copyscape website plagiarism search

  Copyright 2005-2012  Elizabeth Stapel   |   About   |   Terms of Use

 

 Feedback   |   Error?