100 ' MINIMAX VIA ERROR FLUFFING ALGORITHM by Steven A. Ruzinsky. This program demonstrates the determination of polynomial coefficients to a minimum maximum absolute error criterions. The result 110 ' is better that that of Hastings, Approximations for Digital Computers, 1955 Princeton Univiersity Press, p. 138. This program is in IBM Basic. 111 ' Debugged 921206 AvdH seems to work okay in UBASIC 120 ' ----------------------------------------------------------------------112 130 word 8 140 N=3:M=50:ITERATIONS=1000 150 dim X(M,N) 151 dim Y(M) 152 dim XK(N) 153 dim Q(N,N) 154 dim QX(N) 155 dim AK(N) 156 dim A(N) 160 ' ------------------------------------------------------------------------ 170 ' The following fills matrices Y(i) and X(i,j) with data. The function used is SIN(PI*X/2), however, the data is modified so that the minimax criterion is applied to the relative error : 180 for I=1 to M 190 Y(I)=1 200 E=I/M 210 D=1/sin(1.570796327*E) 220 for J=1 to N 230 X(I,J)=D*E^(J+J-1) 240 next J 241 next I 250 ' ------------------------------------------------------------------------ 260 ' The following initiates the Q matrix. It may be necessary to adjust the number in the line 280 for best results. 270 for I=1 to N 280 Q(I,I)=1000000 290 next I 300 ' The following loop with index, K, reiterates the sequential least squares algorithm. Up to limit M, each data point is incorporated once into Q and AK. This results in a least squares fit to the data. Afterwards, the data 320 ' corresponding to the maximum absolute error are reincorporated into Q and AK. 330 EBEST=1 340 for K=1 to ITERATIONS+M 350 if K>M then gosub 740 else gosub 650 360 D=1 370 for J=1 to N 380 QX=0 390 for I=1 to N 400 QX=QX+XK(I)*Q(I,J) 410 next I 420 QX(J)=QX 430 D=D+XK(J)*QX 440 next J 450 for J=1 to N 460 QX=QX(J)/D 470 for I=1 to N 480 Q(I,J)=Q(I,J)-QX(I)*QX 490 next I 491 next J 500 for J=1 to N 510 QX=0 520 for I=1 to N 530 QX=QX+XK(I)*Q(I,J) 540 next I 550 AK(J)=AK(J)+QX*E 560 next J 561 next K 570 ' ------------------------------------------------------------------------ 580 ' The following prints the results : 590 print "Coefficients:":for I=1 to N 600 AK(I)=A(I) 610 print AK(I) 620 next I:gosub 740:end 630 ' ------------------------------------------------------------------------ 640 ' Subroutine for incorporating each data point once : 650 E=Y(K) 660 for I=1 to N 670 XK=X(K,I) 680 XK(I)=XK 690 E=E-AK(I)*XK 700 next I 710 return 720 ' ------------------------------------------------------------------------ 730 ' Subroutine for finding maximum absolute error and corresponding data point : 740 EMAX=0:JMAX=1 750 for J=1 to M 760 E=Y(J) 770 for I=1 to N 780 E=E-X(J,I)*AK(I) 790 next I 800 E=abs(E) 810 if E>EMAX then EMAX=E:JMAX=J 820 next J 830 print "Iterations =",K-M,"Maximum Absolute Error =",EMAX 840 E=Y(JMAX) 850 for I=1 to N 860 XK=X(JMAX,I) 870 XK(I)=XK 880 E=E-AK(I)*XK 890 next I 900 if EMAX