[comp.sys.handhelds] How to use the Solver by program ?

maugis@enac9.enac.dgac.fr (maugis-IEEACS89) (01/23/91)

Hi everybody!

I'm trying to use the SOLVE function of the 48 inside a program. 
It's easy to call the SOLVER menu with the command 30 MENU, but what
I'd like is precisely not see the SOLVER menu, but still use the SOLVE
command. Let me explain my poor self:

Suppose you have stored into EQ the equation:

                   A1*SIN(A2*X) = B1*COS(B2*X)

The SOLVER menu will show :

                A1  A2  X  B1  B2  EXPR=

and you can then enter values for A1,A2,B1,B2 (for example), and finally,
with SHIFT-LEFT and the menu key under X, "Solve for X".

I'd like my program to do just this, (storing values into variables,
and solve the equation), without asking anything to the user. 

Is there a way? Is it just plain and simple? Is there a SYSEVAL 
corresonding to each variable that you can solve?  

Is there anybody out there ?

_______________________________________________________________________________
         __  __     __  __      __  __               
 /| / / /   / / /  /_/ /_      /_/ /_  |/            rey@enac.dgac.fr
/ |/ / /_  /_/ /_ / / __/     / ) /_   /    
_______________________________________________________________________________
         Le boeuf est lent, mais la terre est patiente...

edp@jareth.enet.dec.com (Eric Postpischil (Always mount a scratch monkey.)) (01/24/91)

In article <1991Jan23.125308.25978@enac.dgac.fr>, maugis@enac9.enac.dgac.fr
(maugis-IEEACS89) writes:

>I'm trying to use the SOLVE function of the 48 inside a program. 

The programmable operation for the Solver is called ROOT.  The syntax is:

	expression name guess -> root

The expression can be a program or an algebraic.  The guess can be a real number
or a list of one to three real numbers (see manual for more information). 
Example:

	'X^2=4' 'X' 5 ROOT


				-- edp (Eric Postpischil)
				"Always mount a scratch monkey."
				edp@jareth.enet.dec.com

rrd@hpfcso.HP.COM (Ray Depew) (01/25/91)

Nicolas Rey (maugis@enac9.enac.dgac.fr (maugis-IEEACS89)) asks:


>Hi everybody!

>I'm trying to use the SOLVE function of the 48 inside a program. 
>It's easy to call the SOLVER menu with the command 30 MENU, but what
>I'd like is precisely not see the SOLVER menu, but still use the SOLVE
>command. Let me explain my poor self:

.
.
.

>Is there a way? Is it just plain and simple? Is there a SYSEVAL 
>corresonding to each variable that you can solve?  

Yes, there's a way.  Yes, it's plain and simple.  No, SYSEVALs aren't 
necessary.

You can use the programmable command "ROOT" to solve an equation from inside
a program.  (You can find it in the SOLVE menu.)  The stack diagram is given
below.

Input
-----
Level 3:  equation or equation name
Level 2:  name of the unknown variable
Level 1:  initial guess or guesses
Output
------
Level 1:  value of unknown variable


To use ROOT, you store the values for all the known variables, then you
arrange the stack as shown above and execute ROOT.

For example, suppose you want to solve for X in the equation 'Z=X+Y'.  The
equation is stored in the variable 'PLANE'.  Z = 10 and Y = 2.  The program

   << 10 'Z' STO 2 'Y' STO 'PLANE' 'X' 0 ROOT >>

will return an answer of 8.

Options:
- Level 3 can be the equation itself, 'Z=X+Y', or the equation name, 'PLANE'.
- Level 1 can be a single guess, or a list consisting of two or three (not more)
guesses.  Examples of acceptable guesses for 'X' are
     0
     { 0 1 }
     { 0 1 0.5 }

Limitations:
- ROOT only gives you a number.  It doesn't tell you if the number makes any
sense.  For example, using ROOT on 'Y=ABS(X)', solving for X when Y is -10,
gives you 8E-11.  Using the SOLVER on 'Y=ABS(X)' tells you that there is an
extremum (local minimum) at X=-8E-4.
- ROOT cannot be used as an algebraic, of the form ROOT('PLANE','X',0).

Other observations:
- The programmable ROOT does not use or modify EQ.
- It appears that ROOT is called as a subroutine by the SOLVER and by the 
PLOTTER's root-finding functions.  Can someone confirm this?
- The programmable ROOT appears in only one paragraph, on page 256 of the
Owner's Manual.  It has an entry on page 782 of the Operation Index, but it
cannot be found at all in the Subject Index.  I don't have my Prgrammer's
Reference Manual handy, but it may have more information about ROOT.

I hope this helps you.  Good luck.

>Is there anybody out there ?

Nobody here but us chickens!

-----------
Regards
Ray Depew
rrd@hpfitst1.hp.com
Disclaimer:  I don't make calculators, I just use them, like the rest of you.

bill@flutter.tv.tek.com (William K. McFadden) (01/26/91)

This is slightly off the topic, but have you ever noticed that when you
press left-shift <name> to solve for <name>, pressing <name> a second
time will cause the 48 to display a running tally of its guesses?  It
consists of two lines, one is the upper limit, and the other is the
lower limit.  This is useful for certain equations that tend to diverge
for some initial guesses.  You can see that it's not getting anywhere
and stop it.

I've been using this feature for at least six months, but haven't seen
anyone mention it.  I don't remember seeing it in the manual, either.
Is it in there?
-- 
Bill McFadden    Tektronix, Inc.  P.O. Box 500  MS 58-639  Beaverton, OR  97077
bill@videovax.tv.tek.com,     {hplabs,uw-beaver,decvax}!tektronix!videovax!bill
Phone: (503) 627-6920                 "SCUD: Shoots Crooked, Usually Destroyed"