APPENDIX “C” - LINEARIZER PROGRAM
The following program, written in GWBASIC
®
, calculates the number of
linear slopes
(segments)
required to linearize a given non-linear relationship
at programmable error levels.
This program calculates two sets of values. One set represents percent of
full scale for the input value and the other represents percent of full scale for
the display value. These values are then used by the program user to compute
the actual input and display scaling points.
To use the program, copy it into any computer with GWBASIC
®
installed.
The program uses, in subroutine 10000, the relationship between the
measured parameter and the display reading. Of course, any non-linear
relationship can be substituted into the subroutine to yield the % of full scale
input and % of full scale display. The program will prompt for
(%)
of full
scale error relative to display readings and any other information pertaining
to the process. Increasing the conformity error decreases the number of linear
slopes required to fit the function. The IMS can accommodate up to nine
linear segments and it is generally desired to use all of them to minimize
linearity error.
1 REM THIS PROGRAM WAS WRITTEN IN GWBASIC
®
UNDER
MS-DOS
®
3.3
2 REM THIS PROGRAM CALCULATES THE NUMBER OF LINEAR
SEGMENTS REQUIRED
3 REM TO CURVE-FIT A GIVEN FUNCTION, SEEN IN LINE NUMBER
10000.
4 REM LINE 10000 MAY BE MODIFIED TO ANY MATHEMATICAL
EXPRESSION
5 REM INCLUDING THOSE WITH PROPORTIONAL CONSTANTS
AND MULTIPLE TERMS
10 CLS
15 PRINT “
CURVE FITTING PROGRAM”
16 PRINT “”
30 DIM PA(30)
40 DIM DA(30)
50 INPUT “ENTER CURVE FITTING ERROR (%) > ”,E
60 P = 10000
70 GOSUB 10000
75 CR=D/P
80 ER=D*E*.01
110 CLS
111 SG=SG+1
112 PRINT “
CALCULATING LINEAR SEGMENT ”;SG
115 IF P2 > =10000 THEN A=1:GOTO 1000
117 P2=P2+10
130 P=P1
140 GOSUB 10000
150 D1=D
170 P=P2
180 GOSUB 10000
190 D2=D
210 M=(D2-D1)/(P2-P1)
220 B=D1-(P1*M)
240 PT=P1
245 AD=(P2-P1)/6
250 PT=PT+AD
260 P=PT
270 GOSUB 10000
280 DT=D
290 DT1=(PT*M)+B
310 IF ABS(DT1-DT) > ER THEN 500
320 IF PT < P2 THEN GOTO 250
330 GOTO 115
500 P2=P2+10
510 D2=(P2*M)+B
515 P=P2
520 GOSUB 10000
550 IF ABS(D-D2) < ER THEN 500
1000 PA(SG)=P2/100
1020 DA(SG)=D2/CR/100
1200 P1=P2
1210 D1=D2
1216 IF A1 < > THEN GOTO 110
-43-