CurveP - A curve fitting program

Description

J E Patterson - jepspectro.com - version 20150903

The program fits data that may be linear at low x,y amplitudes but y falls off at higher x values. This is a common issue in many physical systems. x1, y1 should preferably be on the linear part of the curve. CurveP is not a regression. It assumes that the data is reasonably precise. Linear and power curves also work well.

The equation used is y = scale*x^order+slope*x*exp(-factor*x). See jepspectro.com.

Originally chart recorders were used to obtain data which occupied the y axis, leaving interpreted results naturally plotted on the x axis, when graphed on the same paper. Here we are using y as the equation output axis.

x is first normalised, the equation solved and un-normalised to get y.
The equation parameters, scale, order, slope and factor are found by entering some standard data.

y1 ENTER, y2 ENTER, y3 f A
x1 ENTER, x2 ENTER, x3 f B

Do not press ENTER after y3 or x3.
y3>y2>y1 and x3>x2>x1.
After normalisation y3 = x3 = 10 so x3 is not saved. y3 is used instead in the program.

The curve runs through the origin and three points (x1,y1) (x2,y2) (x3,y3). The order of the upper part of the curve is displayed.

y input to f C to get x. This uses SOLVE to run f D - y until zero, the solution x is obtained
x input to f D to get y.

If there is a blank value, enter it and subtract the answers.
Enter f USER to avoid the f key during data input.

Test [x,y] data sets [2,2 4,5 5,8] [1,1 2,4 3,9] [1,1 2,2 3,3] [20,3.69 30,8.64 47,22.16]
Enter y data in A and x data in Y. eg. y1 ENTER y2 ENTER y3 f A.
The last data set relates X-ray fluorescence k line energy in keV to the element atomic number - see Moseley's Law.

In this update I have improved the starting values for the iteration and added a refined guess to the stack for Solve. Order is limited to 10.

Program Resources

Labels

Name Description
 A Enter y1, y2, y3 from stack
 B Enter x1, x2, x3 from stack, normalise, label 1 loop
 C Enter y to get x. Also entered on stack for guess
 D Enter x to get y
 1 Iteration loop runs from B to find parameters
 4 RCL .5 (temp1) 1/x STO .5 (temp1)
 5 Curve function-x = 0 for solve

Storage Registers

Name Description Name Description Name Description
 1 y1  7 xscale to normalise x data .4 scale parameter
 2 y2  8 yscale to normalise y data .5 temp1
 3 y3  9 slope parameter = x1/y1 .6 temp2
 4 order parameter - calculated .1 x1 .7 temp3
 5 factor parameter - first guess = 1 .2 x2 .8 xinput
 6 count - use to modify convergence rate .3 Order parameter - first guess ln(y3/y2)/ln(x3/x2) .9 yinput

Program

Line Display Key Sequence
000   
001 42;21;11 f LBL A
002 44 8   STO 8
003 33   R⬇
004 44 2   STO 2
005 33   R⬇
006 44 1   STO 1
007 45 8   RCL 8
008 1   1
009 0   0
010 44 3   STO 3
011 10   ÷
012 44;10; 2   STO ÷ 2
013 44;10; 1   STO ÷ 1
014 43 32 g RTN
015 42;21;12 f LBL B
016 44 7   STO 7
017 33   R⬇
018 44 .2   STO . 2
019 33   R⬇
020 44 .1   STO . 1
021 45 7   RCL 7
022 45 3   RCL 3
023 10   ÷
024 44;10; .2   STO ÷ . 2
025 44;10; .1   STO ÷ . 1
026 45 3   RCL 3
027 45 2   RCL 2
028 10   ÷
029 43 12   g LN
030 45 3   RCL 3
031 45 .2   RCL . 2
032 10   ÷
033 43 12   g LN
034 10   ÷
035 44 4   STO 4
036 44 .3   STO . 3
037 1   1
038 44 5   STO 5
039 0   0
040 44 6   STO 6
041 45 1   RCL 1
042 45;10; .1   RCL ÷ . 1
043 44 9   STO 9
044 42;21; 1 f LBL 1
045 1   1
046 44;40; 6   STO 6
047 45 3   RCL 3
048 45 4   RCL 4
049 43;30; 7   g TEST x>y
050 45 .3   RCL . 3
051 44 4   STO 4
052 45 3   RCL 3
053 45 5   RCL 5
054 45;20; 3   RCL 3
055 16   CHS
056 12   ℯˣ
057 45;20; 3   RCL 3
058 45;20; 9   RCL 9
059 30   
060 45 3   RCL 3
061 45 4   RCL 4
062 43;30; 2   g TEST x<0
063 45 .3   RCL . 3
064 44 4   STO 4
065 14   
066 10   ÷
067 44 .4   STO . 4
068 45;10; 1   RCL ÷ 1
069 45 .1   RCL . 1
070 45 4   RCL 4
071 14   
072 20   
073 44 .5   STO . 5
074 1   1
075 43;30; 8   g TEST x<y
076 32 4   GSB 4
077 1   1
078 45 .5   RCL . 5
079 30   
080 43 12   g LN
081 16   CHS
082 45;10; .1   RCL ÷ . 1
083 44 5   STO 5
084 45;20; .2   RCL . 2
085 16   CHS
086 12   ℯˣ
087 45;20; .2   RCL . 2
088 45;20; 9   RCL 9
089 45 .4   RCL . 4
090 45 .2   RCL . 2
091 45 4   RCL 4
092 14   
093 20   
094 40   
095 44 .6   STO . 6
096 45 2   RCL 2
097 45;10; 3   RCL ÷ 3
098 3   3
099 0   0
100 20   
101 45;10; 6   RCL ÷ 6
102 11   √x̅
103 45;20; .6   RCL . 6
104 45 .6   RCL . 6
105 45;30; 2   RCL 2
106 10   ÷
107 15   1/x
108 1   1
109 40   
110 44 .7   STO . 7
111 45;20; 4   RCL 4
112 44 4   STO 4
113 45 .7   RCL . 7
114 1   1
115 30   
116 43 16   g ABS
117 1   1
118 26   EEX
119 16   CHS
120 6   6
121 43;30; 8   g TEST x<y
122 22 1   GTO 1
123 45 4   RCL 4
124 43 32 g RTN
125 42;21;14 f LBL D
126 44 .8   STO . 8
127 45;10; 7   RCL ÷ 7
128 45 3   RCL 3
129 20   
130 44 .8   STO . 8
131 45 4   RCL 4
132 14   
133 45;20; .4   RCL . 4
134 45 5   RCL 5
135 45;20; .8   RCL . 8
136 16   CHS
137 12   ℯˣ
138 45;20; .8   RCL . 8
139 45;20; 9   RCL 9
140 40   
141 45;20; 8   RCL 8
142 45 3   RCL 3
143 10   ÷
144 43 32 g RTN
145 42;21;13 f LBL C
146 44 .9   STO . 9
147 36   ENTER
148 42;10; 5   f SOLVE 5
149 43 32 g RTN
150 42;21; 4 f LBL 4
151 45 .5   RCL . 5
152 15   1/x
153 44 .5   STO . 5
154 43 32 g RTN
155 42;21; 5 f LBL 5
156 32 14   GSB D
157 45;30; .9   RCL . 9
158 43 32 g RTN