Hello,

It seems I forgot how to use MVAR on HP42S:

I entered this stupid program:

LBL "COS"

MVAR "X"

RCL "X"

COS

RTN

Then when I do XEQ "COS", the answer is "Nonexistent", instead of letting me enter a value and press "X" to calculate cosinus. Why ?

I feel as stupid as my program ...

Thank you

Do you actually have a variable called "X"?

If not, the error message you're getting is a result of the calculator attempting to recall (RCL) a variable that does not exist.

If you haven't already done so, I would suggest reading chapter 9 of the HP-42S user manual, which is the chapter that deals with program input and output. MVAR doesn't display any menus, all it does is tell the calculator that the variable is to be part of the menu if the menu is displayed with VARMENU.

As mentioned, the error is because you’ve never created X in memory.

As written, your program requires that you store the value of interest into X and then execute COS. That’s not what you describe you wanted to do. Maybe you’re confused because MVAR is typically used with a solver programs or much larger, non-trivial programs with LOTS of variables.

I find it easiest to always create the variables used first before entering the program with:

STO

Shift

Alpha (enter key)

Then type out the name

EXIT when done

Then when you use MVAR or RCL (or anything that references a variable), you can just press the upper row key for that variable. If you have lots of them, you’ll have to use the up/down arrow keys to find the one of interest.

Take away: trivial programs don’t use/need MVAR. What are you actually trying to accomplish? I doubt it is to create a program to calculate a cosine...

(06-07-2020 08:09 PM)Pekis Wrote: [ -> ]Hello,

It seems I forgot how to use MVAR on HP42S:

I entered this stupid program:

LBL "COS"

MVAR "X"

RCL "X"

COS

RTN

Then when I do XEQ "COS", the answer is "Nonexistent", instead of letting me enter a value and press "X" to calculate cosinus. Why ?

Change your MVAR "X" to INPUT "X" and see if it does what you want. No need to previously create the variable "X".

V.

Hello,

Thanks for your answers.

All I wanted to do was a solver program to solve internal rate of return (IRR) of a cash flow set (including frequency for each cash flow).

I was rusty and this is how it ended up:

CF = Preexisting Cash flow matrix (amount in column 1, frequency in column 2, CF(1,1) < 0)

Use Solver with NPV to find IRR (Enter guess for interest rate "IR" (e.g. use 0.1 for 10%))

XEQ NPV alone calculates Net Present Value for the CF cash flow set (with "IR" value)

R03: Intermediary future value

R04: Intermediary total number of cash flows

R05: Current cash flow amount

R06: Current cash flow frequency

Code:

00 { 70-Byte Prgm }

01 LBL "NPV"

02 MVAR "IR"

03 INDEX "CF"

04 0

05 STO 03

06 STO 04

07 LBL 00

08 RCLEL

09 STO 05

10 J+

11 RCLEL

12 STO 06

13 STO+ 04

14 LBL 01

15 1

16 RCL+ "IR"

17 RCL× 03

18 RCL+ 05

19 STO 03

20 DSE 06

21 GTO 01

22 J+

23 FC? 77

24 GTO 00

25 1

26 RCL+ "IR"

27 1

28 RCL- 04

29 Y↑X

30 RCL× 03

31 RTN

32 END

Thanks !

I had to try that out, too:

NPV and IRR
I you want it to work like yours, you can leave out the lines referring to NPV:

(line 05 MVAR "NPV" and line 57 RCL- "NPV")

Then, to get the IRR, SOLVE the program "NPV".

To get the NPV, provide the values for CF0, CFj and IRR% (you can do that interactively with VARMENU "NPV", that is shift-PGM FCN, up, VARM) , and XEQ "NPV".

Cheers, Werner