HP Forums
(50G) Question, has anyone programmed gauss's... - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50G) Question, has anyone programmed gauss's... (/thread-1522.html)



(50G) Question, has anyone programmed gauss's... - CosmicTruth - 06-02-2014 11:12 PM

has anyone wrote program to solve gauss's shoelace formula with a 50G?
http://en.wikipedia.org/wiki/Shoelace_formula


RE: 50G Question, has anyone programmed gauss's... - Thomas Klemm - 06-03-2014 02:33 AM

(06-02-2014 11:12 PM)CosmicTruth Wrote:  has anyone wrote program to solve gauss's shoelace formula with a 50G?

Code:
\<<
  DUP HEAD +
  2 \<< CROSS \>> DOSUBS
  \GSLIST ABS 2 /
\>>
Example:
{
[ 2 1 ]
[ 4 5 ]
[ 7 8 ]
}


Area = 3


RE: 50G Question, has anyone programmed gauss's... - CosmicTruth - 06-03-2014 11:02 AM

(06-03-2014 02:33 AM)Thomas Klemm Wrote:  
(06-02-2014 11:12 PM)CosmicTruth Wrote:  has anyone wrote program to solve gauss's shoelace formula with a 50G?

Code:
\<<
  DUP HEAD +
  2 \<< CROSS \>> DOSUBS
  \GSLIST ABS 2 /
\>>
Example:
{
[ 2 1 ]
[ 4 5 ]
[ 7 8 ]
}


Area = 3

Thanks for reply, whats GSLIST?
the \GSLIST is erroring this, but nice code. i get 'GSLIST/2.'

edit: GOTIT! the statistics EList function... this is good thanks


RE: 50G Question, has anyone programmed gauss's... - Massimo Gnerucci - 06-03-2014 11:13 AM

(06-03-2014 11:02 AM)CosmicTruth Wrote:  Thanks for reply, whats GSLIST?
the \GSLIST is erroring this, but nice code. i get 'GSLIST/2.'

\GSLIST == ∑LIST


RE: 50G Question, has anyone programmed gauss's... - CosmicTruth - 06-03-2014 11:40 AM

it works! thank you all so much for this code!
i'm happy Smile


RE: 50G Question, has anyone programmed gauss's... - Thomas Klemm - 06-04-2014 07:03 AM

This program is for the HP-42S:

Code:
00 { 39-Byte Prgm }
01 LBL "AREA"
02 ENTER
03 DIM?
04 ×
05 X<>Y
06 0
07 X<>Y
08 EDIT
09 LBL 00
10 ENTER
11 →
12 CROSS
13 +
14 ENTER
15 OLD
16 DSE ST Z
17 GTO 00
18 EXITALL
19 X<>Y
20 ABS
21 2
22 /
23 END

Example:
Consider the polygon defined by the points (3,4), (5,11), (12,8), (9,5), and (5,6).

1 ENTER NEWMAT
x: [ 1×1 Matrix ]

0 ENTER COMPLEX +
x: [ 1×1 Cpx Matrix ]

EDIT GROW
3 ENTER 4 COMPLEX →
5 ENTER 11 COMPLEX →
12 ENTER 8 COMPLEX →
9 ENTER 5 COMPLEX →
5 ENTER 6 COMPLEX
EXIT
x: [ 5×1 Cpx Matrix ]

XEQ "AREA"
y: [ 5×1 Cpx Matrix ]
x: 30



RE: 50G Question, has anyone programmed gauss's... - CosmicTruth - 06-07-2014 12:41 PM

(06-04-2014 07:03 AM)Thomas Klemm Wrote:  This program is for the HP-42S:

Code:
00 { 39-Byte Prgm }
(clipped)

Example:
Consider the polygon defined by the points (3,4), (5,11), (12,8), (9,5), and (5,6).
(clipped)
XEQ "AREA"
y: [ 5×1 Cpx Matrix ]
x: 30

This is great and provided another great example, I have difficulty comparing the code or even seeing how it works because I don't have a 42S. I would have difficulty porting 42S code to my 50G, and I do wish 50G had "LBL" and "GOTO" like my old 41 did. I added a front end to the original 50G code above, so I can post it if anyone is interested? still a 50G work in progress but I have it asking for input and it stops and calculates if 0, 0 is entered.


RE: 50G Question, has anyone programmed gauss's... - CosmicTruth - 06-07-2014 12:52 PM

OK so after 30 seconds no one was interested but I'm going to post this 50G code anyhow in hopes someone will look at it and give some pointers...

Code:

%%HP: T(3)A(D)F(.);
\<< CLEAR
   DO "X Y ?
0 0 TO END" { ":X:
:Y:" { 1. 0. } V } INPUT OBJ\-> \->V2
  UNTIL DUP [ 0. 0. ] ==
  END DROP DEPTH \->LIST DUP HEAD + 2.
  \<< CROSS
  \>> DOSUBS \GSLIST ABS 2. /
\>>

This just asks for input till 0,0 is input then calculates the area.

Next (someday) I plan to sum the end areas into a volume using average end area * length.


RE: 50G Question, has anyone programmed gauss's... - C.Ret - 09-21-2014 04:36 PM

Here is a version for HP28S/C and any other old style RPL :

Code:

« DUP SIZE → LCoord s         @  LCoord list of vectors - s size of the list - keep both in stack
  « [0 0 0]                   @  Initialize summation of cross products
    1 s FOR i
       LCoord i GETI          @  Get i-th vetor and prepare to get next one vector
       ROT ROT GET            @  Rotate stack and get (i+1)-th vector
       CROSS +                @  Compute cross product and add into summation
    NEXT
    ABS 2 /                   @  Area is the halb the norm of sum
  »
»