PH206 Lab Assignment No. - 9: Mayank Sharma 180121022
PH206 Lab Assignment No. - 9: Mayank Sharma 180121022
- 9
Mayank Sharma 180121022
1
46. Ztrans = np.transpose(Z)
47. C = np.linalg.inv(np.matmul(Ztrans,Z))
48.
49. D = Dfunc(X,Y,a0[j], a1[j])
50.
51. if j == 0:
52. sqerror = [sqsum(D)]
53. if j != 0:
54. sqerror = np.append(sqerror, [sqsum(D)], axis = 0)
55.
56. A = np.matmul(C,np.matmul(Ztrans,D))
57.
58. a0 = np.append(a0, [a0[j] + A[0][0]], axis=0)
59. a1 = np.append(a1, [a1[j] + A[1][0]], axis=0)
60.
61. e0 = abs(((a0[j+1] - a0[j])/(a0[j+1])) * 100)
62. e1 = abs(((a1[j+1] - a1[j])/(a1[j+1])) * 100)
63.
64. if e0 < 0.001: #Checking the error
65. if e1 < 0.001:
66. break
67.
68. return a0,a1,sqerror,j
69.
70. print(operate(X,Y,a0,a1))
In the above code, the Gauss Newton method has been applied to find the values of
a0 and a1 that minimize the square sum error with error percentage as 0.01%.
Output
Value of square sum error after each iteration - [0.02475064, 0.02424071, 0.00066269,
0.00066166, 0.00066166]
Number of Iterations - 4
2
3