Post Reply 
(34S) Quadratic fit
03-24-2017, 02:23 AM (This post was last modified: 06-15-2017 01:20 PM by Gene.)
Post: #1
(34S) Quadratic fit
This program reproduces original functionality of 30b which has been lost in the upgrade to 34s.

It allows entry of arbitrary number of data points (yk,xk). Then it calculates coefficients of the least squares quadratic polynomial Ax²+Bx+C and allows to calculate its values at different points x.

Code:

// (C) 2013 Andrew Nikitin
// Fit quadratic polynomial to empirical data

// program operates in stack size 4
// uses regJ and regK to accumulate Σx^3 and Σ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

// Once all the points have been entered,
// calculate coefficients (needs at least 3 points):
//   [B]
// Result:
//   a=regA=regZ
//   b=regB=regY
//   c=regC=regX
//   (order compatible with SLVQ)

// Evaluate Ax²+Bx+C polynomial:
//   x [C]
// Result:
//   Ax²+Bx+C

0001 LBL'QF'
0002 SSIZE4
0003 CLΣ
0004 CLx
0005 STO J
0006 STO K
0007 XEQ 00
0008 STOP
0009 XEQ A
0010 BACK 2
0011 LBL A
0012 Σ+
0013 RCL L
0014 ENTER↑
0015 x³
0016 STO+ J
0017 ×
0018 STO+ K
0019 LBL 00
0020 CLx
0021 nΣ
0022 RTN
0023 LBL 65
0024 Σ-
0025 RCL L
0026 ENTER↑
0027 x³
0028 STO- J
0029 ×
0030 STO- K
0031 GTO 00
0032 LBL B
0033 LocR 016
0034 RCL K
0035 STO .03
0036 RCL J
0037 STO .02
0038 STO .06
0039 # 002
0040 nΣ
0041 x≤? Y
0042 ERR 15
0043 STO .07
0044 Σx
0045 STO .04
0046 STO .08
0047 Σx²
0048 STO .01
0049 STO .05
0050 STO .09
0051 Σy
0052 STO .12
0053 Σxy
0054 STO .11
0055 Σx²y
0056 STO .10
0057 1
0058 1
0059 3
0060 .
0061 0
0062 3
0063 0
0064 3
0065 ENTER↑
0066 1
0067 2
0068 2
0069 .
0070 0
0071 3
0072 0
0073 1
0074 # 125
0075 LINEQS
0076 RCL .15
0077 STO A
0078 RCL .14
0079 STO B
0080 RCL .13
0081 STO C
0082 RTN
0083 LBL C
0084 ENTER↑
0085 RCL× A
0086 RCL+ B
0087 ×
0088 RCL+ C
0089 RTN
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)