WP34s program submission: Quadratic fit - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: WP34s program submission: Quadratic fit (/thread-244920.html) WP34s program submission: Quadratic fit - Andrew Nikitin - 06-11-2013 This is an implementation of quadratic fit for WP-34s. If only 3 points are entered, this may be used for quadratic interpolation. Similar function was implemented in HP30b, if you missed it, here it is. ```// (C) 2013 Andrew Nikitin // Fit quadratic polynomial to empirical data // program operates in stack size 4 // uses regJ and regK to accumulate [SIGMA]x^3 and [SIGMA]x^4 // uses stat registers to accumulate other sums // stores coefficients of quadrature fit in regA, regB, regC // Initialize: // XEQ'QF' // Clears sums, but not coefficients // Enter point: // y ENTER x R/S (or [A]) // Result: // number of points entered so far // Calculate coefficients (needs at least 3 points): // [B] // Result: // a=regA=regZ // b=regB=regY // c=regC=regX // (order compatible with SLVQ) // Evaluate Ax[^2]+Bx+C polynomial: // x [C] // Result: // Ax[^2]+Bx+C LBL'QF' SSIZE4 CL[SIGMA] CLx STO J STO K XEQ 00 STOP XEQ A BACK 002 // Accumulate sums, including [SIGMA]x^3 and [SIGMA]x^4 LBL A [SIGMA]+ RCL L ENTER x^3 STO+ J * STO+ K LBL 00 CLx n[SIGMA] RTN // delete point LBL 65 // XEQ - [SIGMA]- RCL L ENTER x^3 STO- J * STO- K GTO 00 // Fit quadratic LBL B LocR 016 RCL K STO .03 RCL J STO .02 STO .06 # 002 n[SIGMA] x<=? Y ERR 15 STO .07 [SIGMA]x STO .04 STO .08 [SIGMA]x[^2] STO .01 STO .05 STO .09 [SIGMA]y STO .12 [SIGMA]xy STO .11 [SIGMA]x[^2]y STO .10 1 1 3 . 0 3 0 3 ENTER 1 2 2 . 0 3 0 1 # 125 LINEQS RCL .15 STO A RCL .14 STO B RCL .13 STO C RTN // Evaluate Ax^2+Bx+C polynomial at regX LBL C ENTER RCL* A RCL+ B * RCL+ C RTN END ``` Re: WP34s program submission: Quadratic fit - Marcus von Cube, Germany - 06-13-2013 Hi Andrew, nice submission. :-) It will find its way into the library if Pauli or I find the time to integrate it. Re: WP34s program submission: Quadratic fit - Paul Dale - 06-13-2013 It is in the library now :) I've not included it in the standard library in flash. - Pauli