Subject: ISOL & ROOTS (Solver for Trig Equations?)
From: jhmeyers@miu.edu (John H Meyers)
Date: 1997/02/16
Newsgroups: comp.sys.hp48

In article <19970213023400.VAA24334@ladder01.news.aol.com>,
<compmain@aol.com> <CompMain.Rep1@usa.net> writes:

> Does a program exist for solving Trigonomic equations, aside from
> built in solver, that will give me all possible [roots] of the eq?

  "All possible" may be pushing it a bit, since there are infinitely
  many roots of 'SIN(X)=0' for example; however, the HP48 can
  sometimes solve symbolically for arbitrary roots, e.g.

    -1 CF DEG 'SIN(X)=0' 'X' ISOL --> 'X=180*n1'

            'SIN(X^2)=0' 'X' ISOL --> 'X=s1*Sqrt(180*n1)'

  The arbitrary sign 's1' and integer 'n1' are discussed
  near page 20-16 of the G/GX User's Guide.

  However, 

    'SIN(X^2)+COS(X)=0' 'X' ISOL --> Error: Unable to Isolate

  If you will settle for finding all numerical roots located over
  an interval, then try the ROOTS program, which is similar to the
  built-in ROOT, but instead of supplying guess(es), you specify the
  endpoints of an interval and an increment (step size) for searching;
  the program checks the endpoints of each step and invokes the
  internal ROOT program whenever the function has changed sign
  between the endpoints of any step, and it accumulates a list
  of all the roots thus located.

Stack diagram:

  'function' 'x' start end increment --> { list of roots }

  The "function" may be an expression, equation, or program.
  'x' is the symbol naming the variable being solved for.

Program (ready for downloading using Kermit, or manual typing):

%%HP: T(3); @ \-> is right-arrow, etc.
@ ROOTS - search an interval for roots, HP48G/GX
\<< \-> f x s e i \<< { } @ extra list for fixing SEQ bug if no roots
  { y x STO f \->NUM y i + x STO f \->NUM * 0 \<= @ sign change
      { f x y DUP i + 2 \->LIST ROOT } IFT } 'y' s e i + i SEQ \>>
  IF DUP SIZE THEN + SORT DUP 1 \<< DUP2 SAME { DROP } IFT \>> DOLIST
  SWAP DROP END \>> @ sorted unique roots in result list
@ 243.5 bytes (on stack), #2274h checksum

Example:

  RAD 'SIN(X^2)+COS(X)=0' 'X' 0 3 .1 --> { 1.7276 2.7276 2.8534 }

  This takes about 13 seconds using an increment of .1 as shown,
  or about 11 seconds using an increment of .2

  Using a smaller increment takes more time;
  using too coarse an increment may fail to discover some of the roots.

  Why is there a difference of exactly 1 between the first two roots?
  (yes, even when viewed with full 12-digit precision)

-----------------------------------------------------------
With best wishes from:  John H Meyers  ( jhmeyers@mum.edu )