I think this provides an HP 200LX HP CALC Solver function that solves all markup, cost, price, margin (MU CST PRC MAR) problems, finding

all possible solution variables by solving for

any possible solution variable. It requires that all 4 variables start as 0, then only meaningful situations be solved. I believe

this could have been put in the HP 10bii and HP 10bii+ firmware. First, simplify variables:

c = CST

p = PRC

u = MU/100

g = MAR/100

Next, there are only 12 meaningful input-output cases. # = case number, Inp = Input(s), S = Solve for, Other = remaining variable to solve for.

Code:

`# Inp S Exp Other`

== === = ======= =====

01 g u = g/(1-g) none

02 g,c u = g/(1-g) p

03 g,p u = g/(1-g) c

04 c,p u = (p-c)/c g

05 u g = u/(1+u) none

06 u,c g = u/(1+u) p

07 u,p g = u/(1+u) c

08 c,p g = (p-c)/p u

09 p,u c = p/(1+u) g

10 p,g c = p*(1-g) u

11 c,u p = c*(1+u) g

12 c,g p = c/(1-g) u

A long nested if-then-else statement is used, based on the S() function and inputs being zero or non-zero. For example S(u) means the user is solving for u. "S(u) & c & p" means the user is solving for u and both c and p are non-zero.

The order of cases is important! SOLVER solves by iterating the variable being solved for, searching for a 0 in the expression provided. Consider the 3 S(u) cases. After "S(u) & c & p" is known to be false, it must be true that either c or p (but not both) is an input. In the "S(u) & c" case, once p is defined during its first iteration, further iterations happen in the "S(u) & c & p" case. SOLVER also evaluates the L(var,exp) function (let var have value exp) before any other operators.

In the following table, #, Inp, and S agree with the table above. In the S column the variable in () is the Other variable in the table above. Test shows how SOLVER will identify the case given, in order. [] indicates things that are known, due to prior IF clauses failing, so they need not be tested for. Expression is what SOLVER will try to set to 0.

Code:

`# Inp S Test Expression`

== === ===== =============== =======================

01 g u c=0 & p=0 u - g/(1-g)

05 u g c=0 & p=0 u - g/(1-g)

04 c,p u (g) S(u) & c & p u - L(g,(p-c)/p)/(1-g)

02 g,c u (p) S(u) & c u - (L(p,c/(1-g))-c)/c

03 g,p u (c) S(u) [& p] u - (p-L(c,p*(1-g)))/c

08 c,p g (u) S(g) & c & p g - L(u,(p-c)/c)/(1+u)

06 u,c g (p) S(g) & c g - (L(p,c*(1+u))-c)/p

07 u,p g (c) S(g) [& p] g - (p-L(c,p/(1+u)))/p

09 p,u c (g) S(c) & u [& p] c - p*(1-L(g,u/(1+u)))

12 p,g c (u) S(c) [& p & g] c - p/(1+L(u,g/(1-g)))

11 c,u p (g) S(p) & u [& c] p - c/(1-L(g,u/(1+u)))

10 c,g p (u) [S(p) & c & g] p - c*(1+L(u,g/(1-g)))

The above table leads to the following HP 200LX SOLVER function.

Code:

`IF(c=0 AND p=0, u - g/(1-g),`

IF(S(u) AND c AND p, u - L(g,(p-c)/p)/(1-g),

IF(S(u) AND c, u - (L(p,c/(1-g))-c)/c,

IF(S(u), u - (p-L(c,p*(1-g)))/c,

IF(S(g) AND c AND p, g - L(u,(p-c)/c)/(1+u),

IF(S(g) AND c, g - (L(p,c*(1+u))-c)/p,

IF(S(g), g - (p-L(c,p/(1+u)))/p,

IF(S(c) AND u, c - p*(1-L(g,u/(1+u))),

IF(S(c), c - p/(1+L(u,g/(1-g))),

IF(S(p) AND u, p - c/(1-L(g,u/(1+u))),

p - c*(1+L(u,g/(1-g)))

))))))))))

That is what I used for development and test. Changing variable names and ordering them as they are on the HP 10bii+ results in the following HP 200LX Solver function.

Code:

`! Clear Data before each use. !`

0*(MU+CST+PRC+MAR) + ! order menu variables !

IF(CST=0 AND PRC=0,

MU - MAR/(1-MAR/100),

IF(S(MU) AND CST AND PRC,

MU - L(MAR,100*(PRC-CST)/PRC)/(1-MAR/100),

IF(S(MU) AND CST,

MU - 100*(L(PRC,CST/(1-MAR/100))-CST)/CST,

IF(S(MU),

MU - 100*(PRC-L(CST,PRC*(1-MAR/100)))/CST,

IF(S(MAR) AND CST AND PRC,

MAR - L(MU,100*(PRC-CST)/CST)/(1+MU/100),

IF(S(MAR) AND CST,

MAR - 100*(L(PRC,CST*(1+MU/100))-CST)/PRC,

IF(S(MAR),

MAR - 100*(PRC-L(CST,PRC/(1+MU/100)))/PRC,

IF(S(CST) AND MU,

CST - PRC*(1-L(MAR,MU/(1+MU/100))/100),

IF(S(CST),

CST - PRC/(1+L(MU,MAR/(1-MAR/100))/100),

IF(S(PRC) AND MU,

PRC - CST/(1-L(MAR,MU/(1+MU/100))/100),

PRC - CST*(1+L(MU,MAR/(1-MAR/100))/100)

))))))))))

This development was done using a Windows 10 PC with DOSBox and the 16-bit HPCALC application that is included with the HP 200LX Connectivity Pack. The c p u g function was tested using c=4, p=5, u=0.25, g=0.2 (12 test cases). The MU CST PRC MAR function was tested with MU=25, CST=4, PRC=5, MAR=20 (12 test cases).

Edit 1: Last table before code, case numbers 07 to 09, 05 to 11 (typos).