Monday, June 23, 2014

HP Prime and HP 50g: Moments of Inertia

Source:

Browne, Michael E. Ph. D "Schaum's Outlines: Physics for Engineering and Science" 2nd. Ed McGraw Hill: New York. 2010.

HP Prime: INERTIA

This program demonstrates the use of CHOOSE and CASE


EXPORT INERTIA( )
BEGIN
// EWS 2014-06-24
LOCAL c,a,b,m,r;

CHOOSE(c, "Moment of Inertia",
{"Square", "Rectangle", "Cylinder", "Sphere", "Hoop"});

CASE

IF c==1 THEN INPUT({m,a});
RETURN m*a^2/6; END;

IF c==2 THEN INPUT({m,a,b});
RETURN m*(a^2+b^2)/12; END;

IF c==3 THEN INPUT({m,r});
RETURN m*r^2/2; END;

IF c==4 THEN INPUT({m,r});
RETURN 2*m*r^2/5; END;

IF c==5 THEN INPUT({m,r});
RETURN m*r^2; END;

DEFAULT KILL; END;

END;


HP 50g: INERTIA

6/23/2014



<< 1 1 1 1 1
→ c a b m r
<< "Moment of Inertia"
{ { "Square" 1 }
{ "Rectangle" 2 }
{ "Cylinder" 3 }
{ "Sphere" 4 }
{ "Hoop" 5 } }
1 CHOOSE

IF 0 == THEN KILL END

'c' STO

CASE c 1 == THEN
"m" PROMPT "a" PROMPT
SQ * 6 / END

c 2 == THEN
"m" PROMPT "a" PROMPT SQ
"b" PROMPT SQ + * 12 / END

c 3 == THEN
"m" PROMPT "r" PROMPT SQ *
2 / END

c 4 == THEN
"m" PROMPT "r" PROMPT SQ * 2 *
5 / END

c 5 == THEN
"m" PROMPT "r" PROMPT SQ *
END

END >> >>



Notes:
* I just stored a value in the variables c, a, b, m, and r, and used the right arrow ( → ) to make the variables local.
* The IF 0 == THEN KILL END sequence handles the case the user chooses CANCEL over its options.
* The consecutive PROMPT commands saved space instead of using INFORM.
* INERTIA demonstrates the CASE structure

Eddie

This blog is property of Edward Shore. 2014

5 comments:

  1. Hello,

    I wrote a Compressible Aerodynamics Calculator for my HP Prime (based on the Prof. William J Devenport on-line version http://www.dept.aoe.vt.edu/~devenpor/aoe3114/calc.html) and is working just fine.

    Is it too difficult to port the program to the 50g? (my boss have one.... and liked the program)

    ReplyDelete
    Replies
    1. No, it shouldn't. But it will may take time and patience. Good luck!

      Delete
  2. It is a great post for every blog and for me. Obviously I want to say that this is very important post for learn. Thanks.

    123 hp setup

    ReplyDelete

HP Prime: Area by Quadratic Splines

HP Prime:  Area by Quadratic Splines Introduction The program QUADSUM calculates the area under the curve described by the set o...