Monday 20 December 2010

algorithm to Implement the Polynomial regression algorithm


Algorithm:

Step 1: Start
Step 2: Read n
Step 3: Initialize sumx = 0, sumxsq = 0, sumy = 0, sumxy = 0,
 sumx3 = 0, sumx4 = 0, sumxsq =0
Step 4: Initialize i=0
Step 5: Repeat steps 5 to 7 until i<n
Step 6: Read x,y
Step 7:
Sumx = sumx + x
Sumxsq =sumxsq + pow(x,2)
Sumx3 = sumx3 + pow(x,3)
Sumx4 = sumx4 + pow(x,4)
Sumy = sumy + y
Sumxy = Sumxy + x*y
Sumxsqy = Sumxsqy + pow(x,2) *y

Step 8: Increment I by 1
Step 9: Assign
a[0][0] = n a[0][1] = n a[0][2] = n a[0][3] = n a[1][0] = n a[1][1] = n a[1][2] = n a[1][3] = n a[2][0] = n a[2][1] = n a[2][2] = n a[2][3] = n

Step 10: Initialize i=0
Step 11: Repeat steps 11 to 15 until i<3
Step 12: Initialize j=0
Step 13: Repeat step 13 to 14 until j<=3
Step 14: Write a[i][j]
Step 15: Increment j by 1
Step 16: Increment I by 1
Step 17: Initialize k =0
Step 18: Repeat steps 18 to 27 until k<=2
Step 19: Initialize i=0
Step 20: Repeat step 20 to 26 until i<=2
Step 21: If I not equal to k
Step 22: Assign u=a[i][k]/a[k][k]
Step 23: Initialize j=k
Step 24: Repeat steps 24 and 25 until j<=3
Step 25: Assign a[i][j] = a[i][j] – u *a[k][j]
Step 26: Increment j by 1
Step 27: Increment i by 1
Step 28: Increment k by 1
Step 29: Initialize I =0
Step 30: Repeat steps 31 to 33 until i<3
Step 31: Assign b[i] = a[i][3]/a[i][i]
Step 32: Write I, b[i]
Step 33: Increment I by 1
Step 34: Write b[2],b[i],b[0]
Step 35: Stop


Algorithm



No comments:

Post a Comment