Core code:
1 //using least squares algorithm to find the polynomial2 voidYcleastsquaresfitspline::calculatemultinomialvalues (Const void* Valuesptr,intStrideintNintMfloatAConst3 {4Memset (A,0,sizeof(float)*m);5 6 floatXStep =1.0f/(N-1);7 8 inti,j,k;9 floatz,p,c,g,q,d1,d2,s[ -],t[ -],b[ -];Ten for(i=0; i<=m-1; i++) One { Aa[i]=0.0f; - } - the if(m>N) - { -m=N; - } + if(m> -) - { +m= -; A } at -z=0.0f; - for(i=0; i<=n-1; i++) - { -z=z+xstep*i/(1.0f*n); - } in -b[0]=1.0f; tod1=1.0f*N; +p=0.0f; -C=0.0f; the for(i=0; i<=n-1; i++) * { $p=p+ (xstep*i-z); Panax Notoginsengc=c+Yfgetfloatvalue (valuesptr, Stride, i); - } thec=c/D1; +p=p/D1; Aa[0]=c*b[0]; the if(m>1) + { -t[1]=1.0f; $t[0]=-p; $D2=0.0f; -C=0.0f; -g=0.0f; the - for(i=0; i<=n-1; i++)Wuyi { theq=xstep*i-z-p; -d2=d2+q*Q; WuC=c+yfgetfloatvalue (valuesptr, Stride, i) *Q; -g=g+ (xstep*i-z) *q*Q; About } $c=c/D2; -p=g/D2; -q=d2/D1; -d1=D2; Aa[1]=c*t[1]; +a[0]=c*t[0]+a[0]; the } - $ for(j=2; j<=m-1; J + +) the { thes[j]=t[j-1]; thes[j-1]=-p*t[j-1]+t[j-2]; the if(j>=3) - { in for(k=j-2; k>=1; k--) the { thes[k]=-p*t[k]+t[k-1]-q*B[k]; About } the } the thes[0]=-p*t[0]-q*b[0]; +D2=0.0f; -C=0.0f; theg=0.0f;Bayi for(i=0; i<=n-1; i++) the { theq=S[j]; - for(k=j-1; k>=0; k--) - { theq=q* (xstep*i-z) +S[k]; the } thed2=d2+q*Q; theC=c+yfgetfloatvalue (valuesptr, Stride, i) *Q; -g=g+ (xstep*i-z) *q*Q; the } the thec=c/D2;94p=g/D2; theq=d2/D1; thed1=D2; thea[j]=c*S[j];98t[j]=S[j]; About for(k=j-1; k>=0; k--) - { 101a[k]=c*s[k]+A[k];102b[k]=T[k];103t[k]=S[k];104 } the }106}
Transduction
Related software for: Http://files.cnblogs.com/WhyEngine/TestSpline.zip
Polynomial of the most small-squares algorithm for spline