HP 49g+ User Manual page 694

Graphing calculator
Hide thumbs Also See for 49g+:
Table of Contents

Advertisement

→ x
IF 'x<3' THEN 'x^2' ELSE '1-x' END EVAL "Done" MSGBOX
«
«
» »
and save it under the name 'f2'. Press
indeed available in your variable menu. Verify the following results:
0 @@@f2@@@ Result: 0
3.5 @@@f2@@@ Result: -2.5
These results confirm the correct operation of the IF...THEN...ELSE...END
construct. The program, as written, calculates the function
Note: For this particular case, a valid alternative would have been to use an
IFTE function of the form: 'f2(x) = IFTE(x<3,x^2,1-x)'
Nested IF...THEN...ELSE...END constructs
In most computer programming languages where the IF...THEN...ELSE...END
construct is available, the general format used for program presentation is the
following:
IF logical_statement THEN
program_statements_if_true
ELSE
program_statements_if_false
END
In designing a calculator program that includes IF constructs, you could start
by writing by hand the pseudo-code for the IF constructs as shown above.
For example, for program @@@f2@@@, you could write
IF x<3 THEN
2
x
ELSE
1-x
END
J
and verify that variable @@@f2@@@ is
1.2 @@@f2@@@ Result: 1.44
10 @@@f2@@@ Result: -9
2
x
,
if
x
3
f
(
x
)
2
1
x
,
otherwise
Page 21-49

Advertisement

Table of Contents
loading

Table of Contents