我有个basic的源代码
就是把x-y(16组数对应)算出a(x×x)+b(x)+c=0中的a,b,c,然后拿算出来的y=a(x×x)+b(x)+c用vb画曲线
basic的源代码如下:
10 REM **** Least Sqares Polynomial Approximation ****
20 N=16:M=2
30 DIM X(N),Y(N),S(2*M),T(M),A(M+1,M+2)
40 FOR J=1 TO N:READ X(J),Y(J):NEXT J
50 FOR I=0 TO M
60 T(I)=0:S(I)=0
70 FOR J=1 TO N
80 T(I)=T(I)+Y(J)*X(J)^I
90 S(I)=S(I)+X(J)^I
100 NEXT J
110 NEXT I
120 FOR I=1 TO M:S(M+I)=0
130 FOR J=1 TO N:S(M+I)=S(M+I)+X(J)^(M+I)
140 NEXT J
150 NEXT I
160 REM *** Modified Squarer Method ***
170 FOR I=0 TO M
180 FOR J=0 TO M
190 A(I+1,J+1)=S(I+J):LPRINT TAB(10*J);A(I+1,J+1);
200 NEXT J
210 A(I+1,M+2)=T(I):LPRINT TAB(10*M+12)A(I+1,M+2)
220 NEXT I
230 GOSUB 400
240 REM *** Print Resolutions ***
250 LPRINT
260 FOR I=0 TO M
270 LPRINT "a(";I;")="A(I+1,M+2)
280 NEXT I
290 data 1,4.00,2,6.40,3,8.00,4,8.80,5,9.22,6,9.50,
300 data 7,9.70,8,9.86,9,10.00,10,10.20,11,10.32
310 data 12,10.42,13,10.50,14,10.55,15,10.58,16,10.60
320 end
400 rem *** subroutine ***
410 for i=2 to m+1:a(i,1)=a(i,1)/a(1,1):next i
if m<2 then 530
430 for k=2 tom
440 for j=k to m+2
450 l=1 to k-1
460 a(k,j)=a(k,j)-a(k,l)*a(l,j)
470 next l
480 next j
490 for i=k+1 to m+1
500 a(i,k)=a(k,i)/a(k,k)
510 next i
520 next k
530 for j=m+1 to m+2
540 for l=1 to m
550 a(m+2,j)=a(m+1,j)-a(m+1,l)*a(l,j)
560 next l
570 next j
580 rem *** back substitution ***
590 a(m+1,m+2)=a(m+1,m+2)/(m+1,m+1)
600 for i=m to 1 step -1
610 for l=i+1 to m+1
620 a(j,m+2)=a(i,m+2)-a(i,l)*a(l,m+2)
630 next l
640 a(i,m+2)=a(i,m+2)/a(i,i)
650 next i
[此贴子已经被作者于2006-4-26 22:24:59编辑过]