CURVE FITTING USING POLYNOMIAL REGRESSION

ALGORITHM: 1. Start the program. 2. Declare the input variables. 3. Print the statement to enter the order of polynomial. 4. Read the value ‘op’. 5. Print the statement to enter the number of data points to be entered for each variable. 6. Read the value ‘n’. 7. Print the statement to enter the independent and dependent variables. 8. If (n<= op) print regression is not possible. 9. print the values of polynomial coefficients.

float x[10]. for(i=1. printf("\n Enter the no.of data points to be entered for each variable. float b[10].c[10][10]. main() { intn.&op). scanf("%d".op="). float x[10]).op.n= "). int n.i++) scanf("%f %f".m. X and y \n").a[10].i<=n. if(n<=op) { printf("\n\n REGRESSION IS NOT POSSIBLE \n"). printf("\nEnter the order of polynomial required. float y[10]. . float c[10][10]. float b[10]. void gauss(int n.&x[i]. int m).h> void normal(float x[10].&n).h> #include <conio.&y[i]). float a[10][10]. printf("\nInput data values. printf("\n enter the data valus for independent and dependent variables respectively\n").h> #include <math.y[10].PROGRAM: //C program to use polynomial regression for curve fitting// #include <stdio.b[10].i. scanf("%d".

normal(x.a).k.k++) { c[j][k]=0.i++) c[j][k]=c[j][k]+ pow(x[i].a[i]). l1=k+j-2. float b[10].b. float y[10]. Stop: getch().i<=n.l1.goto Stop. int m) { int i.b.m). printf("\n\n Polynomial coefficients \n\n"). for(j=1.l1).k<=m.c.l2. } m=op+1. float c[10][10].6f". for(i=1.i<=m.j<=m. } void normal(float x[10]. for(i=1.i++) printf("%15.y.n. gauss(m. } .c.0.j.j++) { for(k=1. int n.

j++) { b[j]=0.i<=n.l2).} for(j=1. } } .i++) b[j]=b[j]+y[i]*pow(x[i].i<=n.j.i++) { factor=a[i][k]/pivot. float x[10]) { inti.k. for(k=1.j<=n. l2=j-1. float b[10]. } } void gauss(int n. float a[10][10]. floatpivot. for(i=1.j++) a[i][j]=a[i][j]-factor*a[k][j].sum.0.k<=n-1. b[i]=b[i]-factor*b[k].k++) { pivot=a[k][k]. for(j=k+1.j<=m. for(i=k+1.factor.

for(j=k+1.j++) sum=sum+a[k][j]*x[j]. x[k]=(b[k]-sum)/a[k][k].0.k>=1.j<=n.x[n]=b[n]/a[n][n].k--) { sum=0. } } . for(k=n-1.

Sign up to vote on this title
UsefulNot useful