 HP35s - Regression and Geometric Program - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HP35s - Regression and Geometric Program (/thread-6440.html) HP35s - Regression and Geometric Program - deetee - 06-21-2016 01:26 PM Hi all! I wrote a (huge) program to calculate different regression curves for xy-pairs and some geometric and mechanic values (if the xy-pairs represent a closed polygon). In detail this program calculates: * Regression with inverse function y=A+B/x * Regression with constant function y=A * Regression with linear function y=A+B.x * Regression with quadratic function y=A+Bx+C.x^2 * Regression with logarithmic function y=A+B.ln(x) * Regression with exponential function y=A.exp(B.x) * Regression with ab-power-function y=A.B^x * Regression with power function y=A.x^B * Circumference of polygon * Area of polygon * Center of gravity coordinates (x,y) * Second moments of inertia of area (Ixx, Iyy, Ixy) I got most formulas from http://keisan.casio.com/menu/system/000000000395 (unfortunately a casio page) and https://en.wikipedia.org/wiki/Second_moment_of_area The whole program is menu driven (see attachment; similar to the programs of stefanv): * Main menu: SUM+ - c LR x^y^ G (add xy-pair, remove xy-pair, clear all, calculate parameters of regression, predict y and x values, calculate geometric data) * Submenu calculate parameters: POLYNOM POWER (polynomical- or power-regression) * Submenu calculate polynomical regression: x^-1 x^0 x^1 x^2 (inverse, constant, linear quadratic regression) * Submenu calculate power regression: LN EXP AB PWR (logarithmic, exponential, ab-power, power) * Submenu geometric: C A CGxy MD (circumference, area, center of gravity, moments of deviation) Actually this program is close to the limits of the HP35s. I had to use EQN-formulas for prediction to use less then 1000 lines per label. "Meanwhile calculation" during the input of the xy-pairs needs "a second". As this program does not use the intrinsic regression module of the HP35s, inputs with the SUM+-key are not possible ... instead 3 keys have to be pressed (R/S 1 R/S). Example - Linear regression for x1,y1=1,4 and x2,y2=2,5: * XEQs ENTER 3 R/S ... start and clear all * 4 ENTER 1 R/S 1 R/S ... enter first yx-pair (the display shows n=1, and x,y=1i4 the last pair in "complex view") * 5 ENTER 2 R/S 1 R/S ... enter second yx-pair (display: 2, 2i5) * R/S 4 R/S 1 R/S 3 R/S ... to calculate linear coefficients A=3 and B=1 * 0 R/S 5 R/S ... predicts y=3 (and x=-3) value for x=0 (and y=0) Used flags: * Flag 0: clear...SUM+, set...SUM- Used direct variables * a:A * b:B * c:C * d:a… * e:xmv * f:ymv, Gtmp * g:x2mv, Gtmp * h:...mv, Gtmp * i:i indir * j:j indir * k:type * l:loop counter * m:max indir. var (27) * n:n * o:Sxx * p:Sxy * q:Sxx2 * r:Sx2x2 * s:Sx2y * t: S…denominator, tmp * u:x1 * v:y1 * w:xold * x:x * y:y * z:yold * Used indirect variables 1:SUMx 2:SUMy 3:SUMx^2 4:SUMy^2 5:SUMxy 6:SUMx^3 7:SUMx^4 8:SUMx^2y 9:SUMlnx 10:SUMlnx.y 11:SUM(lnx)^2 12:SUMlny 13:SUMln(y^2) 14:SUMx.lny 15:SUMlnx.lny 16:SUM1/x 17:SUM1/x^2 18:SUMy/x 19:SUM(lnx)^2 20:c 21:a 22:CGx 23:Cgy 24:Ixx 25:Iyy 26:Ixy PROGRAM CODE (short version) - S – (Sums) LN=3172 [MAIN MENU] LBLs STOx Rdown STOy 27 STOm STOi STO(i) CLx SF10 „EQN: SUM+ - c LR x^y^ G“ CF10 1 x=y? GTOs042 Rdown 2 x=y? GTOs041 Rdown 3 x=y? GTOs289 Rdown 4 x=y? GTOs304 Rdown 5 x=y? GTOs766 Rdown 6 x=y? GTOs842 GTOs001 [CALCULATE SUMS] [s037] FS?0 +/- STO+(i) RTN [s041] SF0 [s042] 1 FS?0 +/- STO+n 1 STOi RCLx XEQs037 2 STOi RCLy XEQs037 3 STOi RCLx x2 XEQs037 4 STOi RCLy x2 XEQs037 5 STOi RCLx RCLy * XEQs037 6 STOi RCLx 3 y^x XEQs037 7 STOi RCLx 4 y^x XEQs037 8 STOi RCLx x2 RCLy * XEQs037 9 STOi RCLx x>0? LN XEQs037 10 STOi RCLx x>0? LN RCLy * XEQs037 11 STOi RCLx x>0? LN x2 XEQs037 12 STOi RCLy x>0? LN XEQs037 13 STOi RCLy x2 x>0? LN XEQs037 14 STOi RCLy x>0? LN RCLx * XEQs037 15 STOi RCLx x>0? LN RCLy x>0? LN * XEQs037 16 STOi RCLx x<>0? 1/x XEQs037 17 STOi RCLx x2 x<>0? 1/x XEQs037 18 STOi RCLy RCLx x<>0? / XEQs037 19 STOi RCLx x>0? LN x2 XEQs037 FS0? GTOs171 GTOs174 [s171] 1 STO+n GTO191 [s174] 1 RCLn x=y? GTO179 GTO186 [s179] RCLx STOu STOw RCLy STOv STOz GTOs191 [s186] XEQs196 RCLx STOw RCLy STOz [s191] RCLn eqn:X+i*Y CF0 STOP GTOs001 [s196] 20 STOi RCLx RCLw – x2 RCLy RCLz – x2 + SQRTx XEQs037 21 STOi RCLy RCLw * RCLx RCLz * – STOh XEQs037 22 STOi RCLx RCLw + RCLh * XEQs037 23 STOi RCLy RCLz + RCLh * XEQs037 24 STOi RCLy x2 RCLy RCLz * + RCLz x2 + RCLh * XEQs037 25 STOi RCLx x2 RCLx RCLw * + RCLw x2 + RCLh * XEQs037 26 STOi RCLx RCLz * RCLx RCLy * 2 * + RCLw RCLz * 2 * + RCLw RCLy * + RCLh * XEQs037 RTN [CLEAR ALL] [s289] RCLm 1 - STOi [s293] RCLi x<=0? GTOs301 0 STO(i) 1 STO-i GTOs293 [s301] CLVARS STOP GTOs001 [SUBMENU] [s304] CLx SF10 „EQN: POLYNOM POWER“ CF10 1 x=y? GTOs316 Rdown 2 x=y? GTOs557 GTOs001 [SUBMENU - POLYGON] [s316] CLx SF10 „eqn: x-1 x0 x1 x2“ CF10 1 x=y? GTOs336 Rdown 2 x=y? GTOs389 Rdown 3 x=y? GTOs401 Rdown 4 x=y? GTOs447 GTOs001 [CALCULATE REGRESSION COEFFICIENTS - POLYNOM] [s336] 1 STOk 17 STOi 16 STOj RCL(i) RCL(j) x2 RCLn / - STOt 18 STOi 2 STOj RCL(i) RCL(j) 16 STOi RCL(i) x<>y Rdown RCLn / * - RCLt / STOb RCLn / 16 STOi RCL(i) x<>y Rdown * +/- 2 STOi RCL(i) x<>y Rdown RCLn / + STOa RCLb x<>y STOP GTOs001 [s389] 2 STOk 2 STOi RCL(i) RCLn / STOa 0 x<>y STOP GTOs001 [s401] 3 STOk 1 STOi RCL(i) RCLn / STOe 2 STOi RCL(i) RCLn / STOf 3 STOi RCL(i) RCLn / RCLe x2 – STOo 5 STOi RCL(i) RCLn / RCLe RCLf * - STOp RCLo / STOb RCLe * +/- RCLf + STOa RCLb x<>y STOP GTOs001 [s447] 4 STOk 1 STOi RCL(i) RCLn / STOe 2 STOi RCL(i) RCLn / STOf 3 STOi RCL(i) RCLn / STOg 3 STOi RCL(i) RCLn / RCLe x2 – STOo 5 STOi RCL(i) RCLn / RCLe RCLf * - STOp 6 STOi RCL(i) RCLn / RCLe RCLg * - STOq 7 STOi RCL(i) RCLn / RCLg x2 – STOr 8 STOi RCL (i) RCLn / RCLg RCLf * - STOs RCLo RCLr * RCLq x2 – STOt RCLp RCLr * RCLs RCLq * - RCLt / STOb RCLs RCLo * RCLp RCLq * - RCLt / STOc RCLf RCLb RCLe * - RCLc RCLg * - STOa RCLc RCLb RCLa STOP GTOs001 [SUBMENU - POWER] [s557] CLx SF10 „eqn: LN EXP AB PWR“ CF10 1 x=y? GTOs577 Rdown 2 x=y? GTOs623 Rdown 3 x=y? GTOs670 Rdown 4 x=y? GTOs719 GTOs001 [CALCULATE REGRESSION COEFFICIENTS - POWER]  5 STOk 9 STOi RCL(i) RCLn / STOe 2 STOi RCL(i) RCLn / STOf 11 STOi RCL(i) RCLn / RCle x2 – STOo 10 STOi RCL(i) RCLn / RCLe RCLf * - STOp RCLo / STOb RCLe * +/- RCLf + STOa RCLb x<>y STOP GTOs001  6 STOk 1 STOi RCL(i) RCLn / STOe 12 STOi RCL(i) RCLn / STOf 3 STOi RCL(i) RCLn / RCLe x2 – STOo 14 STOi RCL(i) RCLn / RCLe RCLf * - STOp RCLo / STOb RCLe * +/- RCLf + ex STOa RCLb x<>y STOP GTOs001  7 STOk 1 STOi RCL(i) RCLn / STOe 12 STOi RCL(i) RCLn / STOf 3 STOi RCL(i) RCLn / RCLe x2 – STOo 14 STOi RCL(i) RCLn / RCLe RCLf * - STOp RCLo / ex STOb LN RCLe * +/- RCLf + ex STOa RCLb x<>y STOP GTOs001  8 STOk 9 STOi RCL(i) RCLn / STOe 12 STOi RCL(i) RCLn / STOf 19 STOi RCL(i) RCLn / RCLe x2 – STOo 15 STOi RCL(i) RCLn / RCLe RCLf * - STOp RCLo / STOb RCLe * +/- RCLf + ex STOa RCLb x<>y STOP GTOs001 [PREDICTION SPREAD] [s766] RCLk 1 x=y? GTOs799 Rdown 2 x=y? GTOs803 Rdown 3 x=y? GTOs806 Rdown 4 x=y? GTOs810 Rdown 5 x=y? GTOs826 Rdown 6 x=y? GTOs830 Rdown 7 x=y? GTOs834 Rdown 8 x=y? GTOs838 GTOs001 [CALCULATE PREDICTION] [s799] eqn:A*B/X eqn:B/(X-A) STOP GTOs001 [s803] RCLa STOP GTOs001 [s806] eqn:A+B*X eqn: (X-A)/B STOP GTOS001 [s810] SQ(B)-4*A*C STOt x>0? GTOs817 x=0? GTOs819 GTOs821 [s817] eqn: (-B+SQRT(T))/2/C+i*(-B-SQRT(T))/2/C GTOs822 [s819] eqn:-B/2/C GTOs822 [s821] 9,9999 [s822] eqn:C*SQ(X)+B*X+A x<>y STOP GTOs001 [s826] eqn:A+B*LN(X) eqn:EXP((X-A)/B) STOP GTOs001 [s830] eqn:A*EXP(B*X) eqn:LN(X/A)/B STOP GTOs001 [s834] eqn:A*B^X eqn:LN(X/A)/LN(B) STOP GTOs001 [s838] eqn:A*X^B eqn:EXP(LN(X/A)/B) STOP GTOs001 [CALCULATE GEOMETRICS] [s842] RCLu STOx RCLv STOy XEQs196 [s847] CLx SF10 „eqn:C A CGxy MD“ CF10 1 x=y? GTOs867 Rdown 2 x=y? GTOs872 Rdown 3 x=y? GTOs879 Rdown 4 x=y? GTOs901 GTOs847 [s867] 20 STOi RCL(i) STOP GTOs847 [s872] 21 STOi RCL(i) 2 / STOP GTOs847 [s879] 22 STOi 21 STOj RCL(i) RCL(j) / 3 / STOe 23 STOi 21 STOj RCL(i) RCL(j) / 3 / RCLe STOP GTOs847  24 STOi RCL(i) 12 / STOe 25 STOi RCL(i) 12 / STOf 26 STOi RCL(i) 24 / RCLf RCLe STOP GTOs847 Maybe someone can use this or parts of it. If someone finds a bug please drop an answer. I did not make the program very resistant against "misuse" (I only captured some "divisions by 0" and "log(0)" during sums-calculation). Regards deetee PS: To release the occupied indirect memory (approx. 1 kB) press: shiftright CLEAR 6 (CLVARx) 000 and 0 STO I STO(I).