@ -177,7 +177,8 @@
" # compute the residual vector and the norm of each col in the vector res\n",
" # compute the residual vector and the norm of each col in the vector res\n",
" for i in range(len(a)):\n",
" for i in range(len(a)):\n",
" r[:,[i]] = ((1 - a[i])/a[i])*v - ((1/a[i])*I - Pt).dot(x[:,[i]])\n",
" r[:,[i]] = ((1 - a[i])/a[i])*v - ((1/a[i])*I - Pt).dot(x[:,[i]])\n",
" res[i] = sp.sparse.linalg.norm(r[:,[i]], ord='fro') # frobenius norm since l2 norm is not defined for sparse matrices in scipy\n",
" r_i = r[:,[i]].toarray() # r_i is the residual vector for alpha_i\n",
" res[i] = a[i] * np.linalg.norm(r_i, ord = 2)\n",
" \n",
" \n",
" for _ in range(maxit):\n",
" for _ in range(maxit):\n",
" err = np.absolute(np.max(res)) # check if we have converged\n",
" err = np.absolute(np.max(res)) # check if we have converged\n",
@ -187,11 +188,11 @@
"\n",
"\n",
" print(\"\\niter = \", iter)\n",
" print(\"\\niter = \", iter)\n",
" print(\"res: \", res)\n",
" print(\"res: \", res)\n",
" print(\"err = \", err)\n",
" # print(\"err = \", err)\n",
"\n",
"\n",
" # find k as the index of the largest residual\n",
" # find k as the index of the largest residual\n",
" k = int(np.argmax(res))\n",
" k = int(np.argmax(res))\n",
" print(\"k = \", k)\n",
" # print(\"k = \", k)\n",
"\n",
"\n",
" # compute gamma as defined in the paper\n",
" # compute gamma as defined in the paper\n",
" gamma = compute_gamma(res, a, k)\n",
" gamma = compute_gamma(res, a, k)\n",
@ -202,6 +203,7 @@
" H = H[:-1,:] # remove the last row of H\n",
" H = H[:-1,:] # remove the last row of H\n",
" V = V[:,:-1] # remove the last col of V\n",
" V = V[:,:-1] # remove the last col of V\n",
" mv = mv + j # update the number of matrix-vector products\n",
" mv = mv + j # update the number of matrix-vector products\n",
" print(\"mv = \", mv)\n",
"\n",
"\n",
" H_e1 = np.zeros(H.shape[0]) \n",
" H_e1 = np.zeros(H.shape[0]) \n",
" H_e1[0] = 1 # canonical vector e1 of size H.shape[0]\n",
" H_e1[0] = 1 # canonical vector e1 of size H.shape[0]\n",
@ -221,25 +223,30 @@
" V_e1 = sp.sparse.lil_matrix(V_e1) # canonical vector e1 of size V.shape[0]\n",
" V_e1 = sp.sparse.lil_matrix(V_e1) # canonical vector e1 of size V.shape[0]\n",
"\n",
"\n",
" # Update res[k]\n",
" # Update res[k]\n",
" res[k] = a[k]* (sp.sparse.linalg.norm(beta*V_e1.T - V @ y[:,[k]]))\n",
" tmp = beta*V_e1.T - V @ y[:,[k]]\n",
" tmp = tmp.toarray()\n",
" res[k] = a[k] * np.linalg.norm(tmp, ord = 2)\n",
" # res[k] = a[k]* (sp.sparse.linalg.norm(beta*V_e1.T - V @ y[:,[k]]))\n",
"\n",
"\n",
" # multi shift\n",
" # multi shift\n",
" H_new = H\n",
" for i in range(len(a)):\n",
" for i in range(len(a)):\n",
" if i != k and res[i] >= tau :\n",
" if i != k:\n",
" if res[i] >= tau:\n",
" if res[i] >= tau:\n",
" \n",
" \n",
" H = H + ((1-a[i])/a[i] - (1-a[k])/a[k])*sp.sparse.eye(H.shape[0], H.shape[1], format='lil')\n",
" # H = H + ((1-a[i])/a[i] - (1-a[k])/a[k])*sp.sparse.eye(H.shape[0], H.shape[1], format='lil')\n",
" H_new = H + ((1-a[i])/a[i] - (1-a[k])/a[k])*sp.sparse.eye(H.shape[0], H.shape[1], format='lil')\n",
"\n",
"\n",
" # Compute z as described in the paper\n",
" # Compute z as described in the paper\n",
" z1 = H_e1.T*beta\n",
" z1 = H_e1.T*beta\n",
" z1 = z1.reshape(z1.shape[0],1)\n",
" z1 = z1.reshape(z1.shape[0],1)\n",
" z2 = H @ y[:,[1 ]]\n",
" z2 = H @ y[:,[k ]]\n",
" z2 = z2.reshape(z2.shape[0],1)\n",
" z2 = z2.reshape(z2.shape[0],1)\n",
" z = z1 - z2\n",
" z = z1 - z2\n",
"\n",
"\n",
" # Solve the linear system for A and b\n",
" # Solve the linear system for A and b\n",
" A = sp.sparse.hstack([H, z])\n",
" A = sp.sparse.hstack([H_new , z])\n",
" b = (beta*H_e1)\n",
" b = gamma[i]* (beta*H_e1)\n",
"\n",
"\n",
" to_split = sp.sparse.linalg.lsqr(A, b.reshape(b.shape[0],1))[0]\n",
" to_split = sp.sparse.linalg.lsqr(A, b.reshape(b.shape[0],1))[0]\n",
" \n",
" \n",
@ -253,9 +260,9 @@
" # update res[i]\n",
" # update res[i]\n",
" res[i] = (a[i]/a[k])*gamma[i]*res[k]\n",
" res[i] = (a[i]/a[k])*gamma[i]*res[k]\n",
"\n",
"\n",
" else:\n",
" # else:\n",
" if res[i] < tau:\n",
" # if res[i] < tau:\n",
" print(\"res[\", i, \"] is smaller than tau = \", tau, \" at iteration \", iter)\n",
" # print(\"res[\", i, \"] is smaller than tau = \", tau, \" at iteration \", iter)\n",
"\n",
"\n",
" iter += 1\n",
" iter += 1\n",
" x = x_new\n",
" x = x_new\n",
@ -295,504 +302,404 @@
"text": [
"text": [
"\n",
"\n",
"iter = 1\n",
"iter = 1\n",
"res: [0.00558049 0.00351364 0.00166436 0.00031942]\n",
"res: [0.00474342 0.00316228 0.00158114 0.00031623]\n",
"err = 0.005580489988532435\n",
"mv = 99\n",
"k = 0\n",
"\n",
"\n",
"iter = 2\n",
"iter = 2\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 198\n",
"k = 0\n",
"\n",
"\n",
"iter = 3\n",
"iter = 3\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 297\n",
"k = 0\n",
"\n",
"\n",
"iter = 4\n",
"iter = 4\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 396\n",
"k = 0\n",
"\n",
"\n",
"iter = 5\n",
"iter = 5\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 495\n",
"k = 0\n",
"\n",
"\n",
"iter = 6\n",
"iter = 6\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 594\n",
"k = 0\n",
"\n",
"\n",
"iter = 7\n",
"iter = 7\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 693\n",
"k = 0\n",
"\n",
"\n",
"iter = 8\n",
"iter = 8\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 792\n",
"k = 0\n",
"\n",
"\n",
"iter = 9\n",
"iter = 9\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 891\n",
"k = 0\n",
"\n",
"\n",
"iter = 10\n",
"iter = 10\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 990\n",
"k = 0\n",
"\n",
"\n",
"iter = 11\n",
"iter = 11\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1089\n",
"k = 0\n",
"\n",
"\n",
"iter = 12\n",
"iter = 12\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1188\n",
"k = 0\n",
"\n",
"\n",
"iter = 13\n",
"iter = 13\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1287\n",
"k = 0\n",
"\n",
"\n",
"iter = 14\n",
"iter = 14\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1386\n",
"k = 0\n",
"\n",
"\n",
"iter = 15\n",
"iter = 15\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1485\n",
"k = 0\n",
"\n",
"\n",
"iter = 16\n",
"iter = 16\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1584\n",
"k = 0\n",
"\n",
"\n",
"iter = 17\n",
"iter = 17\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1683\n",
"k = 0\n",
"\n",
"\n",
"iter = 18\n",
"iter = 18\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1782\n",
"k = 0\n",
"\n",
"\n",
"iter = 19\n",
"iter = 19\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1881\n",
"k = 0\n",
"\n",
"\n",
"iter = 20\n",
"iter = 20\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 1980\n",
"k = 0\n",
"\n",
"\n",
"iter = 21\n",
"iter = 21\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2079\n",
"k = 0\n",
"\n",
"\n",
"iter = 22\n",
"iter = 22\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2178\n",
"k = 0\n",
"\n",
"\n",
"iter = 23\n",
"iter = 23\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2277\n",
"k = 0\n",
"\n",
"\n",
"iter = 24\n",
"iter = 24\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2376\n",
"k = 0\n",
"\n",
"\n",
"iter = 25\n",
"iter = 25\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2475\n",
"k = 0\n",
"\n",
"\n",
"iter = 26\n",
"iter = 26\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2574\n",
"k = 0\n",
"\n",
"\n",
"iter = 27\n",
"iter = 27\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2673\n",
"k = 0\n",
"\n",
"\n",
"iter = 28\n",
"iter = 28\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2772\n",
"k = 0\n",
"\n",
"\n",
"iter = 29\n",
"iter = 29\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2871\n",
"k = 0\n",
"\n",
"\n",
"iter = 30\n",
"iter = 30\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 2970\n",
"k = 0\n",
"\n",
"\n",
"iter = 31\n",
"iter = 31\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3069\n",
"k = 0\n",
"\n",
"\n",
"iter = 32\n",
"iter = 32\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3168\n",
"k = 0\n",
"\n",
"\n",
"iter = 33\n",
"iter = 33\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3267\n",
"k = 0\n",
"\n",
"\n",
"iter = 34\n",
"iter = 34\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3366\n",
"k = 0\n",
"\n",
"\n",
"iter = 35\n",
"iter = 35\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3465\n",
"k = 0\n",
"\n",
"\n",
"iter = 36\n",
"iter = 36\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3564\n",
"k = 0\n",
"\n",
"\n",
"iter = 37\n",
"iter = 37\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3663\n",
"k = 0\n",
"\n",
"\n",
"iter = 38\n",
"iter = 38\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3762\n",
"k = 0\n",
"\n",
"\n",
"iter = 39\n",
"iter = 39\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3861\n",
"k = 0\n",
"\n",
"\n",
"iter = 40\n",
"iter = 40\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 3960\n",
"k = 0\n",
"\n",
"\n",
"iter = 41\n",
"iter = 41\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4059\n",
"k = 0\n",
"\n",
"\n",
"iter = 42\n",
"iter = 42\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4158\n",
"k = 0\n",
"\n",
"\n",
"iter = 43\n",
"iter = 43\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4257\n",
"k = 0\n",
"\n",
"\n",
"iter = 44\n",
"iter = 44\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4356\n",
"k = 0\n",
"\n",
"\n",
"iter = 45\n",
"iter = 45\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4455\n",
"k = 0\n",
"\n",
"\n",
"iter = 46\n",
"iter = 46\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4554\n",
"k = 0\n",
"\n",
"\n",
"iter = 47\n",
"iter = 47\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4653\n",
"k = 0\n",
"\n",
"\n",
"iter = 48\n",
"iter = 48\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4752\n",
"k = 0\n",
"\n",
"\n",
"iter = 49\n",
"iter = 49\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4851\n",
"k = 0\n",
"\n",
"\n",
"iter = 50\n",
"iter = 50\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 4950\n",
"k = 0\n",
"\n",
"\n",
"iter = 51\n",
"iter = 51\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5049\n",
"k = 0\n",
"\n",
"\n",
"iter = 52\n",
"iter = 52\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5148\n",
"k = 0\n",
"\n",
"\n",
"iter = 53\n",
"iter = 53\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5247\n",
"k = 0\n",
"\n",
"\n",
"iter = 54\n",
"iter = 54\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5346\n",
"k = 0\n",
"\n",
"\n",
"iter = 55\n",
"iter = 55\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5445\n",
"k = 0\n",
"\n",
"\n",
"iter = 56\n",
"iter = 56\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5544\n",
"k = 0\n",
"\n",
"\n",
"iter = 57\n",
"iter = 57\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5643\n",
"k = 0\n",
"\n",
"\n",
"iter = 58\n",
"iter = 58\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5742\n",
"k = 0\n",
"\n",
"\n",
"iter = 59\n",
"iter = 59\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5841\n",
"k = 0\n",
"\n",
"\n",
"iter = 60\n",
"iter = 60\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 5940\n",
"k = 0\n",
"\n",
"\n",
"iter = 61\n",
"iter = 61\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6039\n",
"k = 0\n",
"\n",
"\n",
"iter = 62\n",
"iter = 62\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6138\n",
"k = 0\n",
"\n",
"\n",
"iter = 63\n",
"iter = 63\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6237\n",
"k = 0\n",
"\n",
"\n",
"iter = 64\n",
"iter = 64\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6336\n",
"k = 0\n",
"\n",
"\n",
"iter = 65\n",
"iter = 65\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6435\n",
"k = 0\n",
"\n",
"\n",
"iter = 66\n",
"iter = 66\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6534\n",
"k = 0\n",
"\n",
"\n",
"iter = 67\n",
"iter = 67\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6633\n",
"k = 0\n",
"\n",
"\n",
"iter = 68\n",
"iter = 68\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6732\n",
"k = 0\n",
"\n",
"\n",
"iter = 69\n",
"iter = 69\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6831\n",
"k = 0\n",
"\n",
"\n",
"iter = 70\n",
"iter = 70\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 6930\n",
"k = 0\n",
"\n",
"\n",
"iter = 71\n",
"iter = 71\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7029\n",
"k = 0\n",
"\n",
"\n",
"iter = 72\n",
"iter = 72\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7128\n",
"k = 0\n",
"\n",
"\n",
"iter = 73\n",
"iter = 73\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7227\n",
"k = 0\n",
"\n",
"\n",
"iter = 74\n",
"iter = 74\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7326\n",
"k = 0\n",
"\n",
"\n",
"iter = 75\n",
"iter = 75\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7425\n",
"k = 0\n",
"\n",
"\n",
"iter = 76\n",
"iter = 76\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7524\n",
"k = 0\n",
"\n",
"\n",
"iter = 77\n",
"iter = 77\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7623\n",
"k = 0\n",
"\n",
"\n",
"iter = 78\n",
"iter = 78\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7722\n",
"k = 0\n",
"\n",
"\n",
"iter = 79\n",
"iter = 79\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7821\n",
"k = 0\n",
"\n",
"\n",
"iter = 80\n",
"iter = 80\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 7920\n",
"k = 0\n",
"\n",
"\n",
"iter = 81\n",
"iter = 81\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8019\n",
"k = 0\n",
"\n",
"\n",
"iter = 82\n",
"iter = 82\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8118\n",
"k = 0\n",
"\n",
"\n",
"iter = 83\n",
"iter = 83\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8217\n",
"k = 0\n",
"\n",
"\n",
"iter = 84\n",
"iter = 84\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8316\n",
"k = 0\n",
"\n",
"\n",
"iter = 85\n",
"iter = 85\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8415\n",
"k = 0\n",
"\n",
"\n",
"iter = 86\n",
"iter = 86\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8514\n",
"k = 0\n",
"\n",
"\n",
"iter = 87\n",
"iter = 87\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8613\n",
"k = 0\n",
"\n",
"\n",
"iter = 88\n",
"iter = 88\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8712\n",
"k = 0\n",
"\n",
"\n",
"iter = 89\n",
"iter = 89\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8811\n",
"k = 0\n",
"\n",
"\n",
"iter = 90\n",
"iter = 90\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 8910\n",
"k = 0\n",
"\n",
"\n",
"iter = 91\n",
"iter = 91\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9009\n",
"k = 0\n",
"\n",
"\n",
"iter = 92\n",
"iter = 92\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9108\n",
"k = 0\n",
"\n",
"\n",
"iter = 93\n",
"iter = 93\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9207\n",
"k = 0\n",
"\n",
"\n",
"iter = 94\n",
"iter = 94\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9306\n",
"k = 0\n",
"\n",
"\n",
"iter = 95\n",
"iter = 95\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9405\n",
"k = 0\n",
"\n",
"\n",
"iter = 96\n",
"iter = 96\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9504\n",
"k = 0\n",
"\n",
"\n",
"iter = 97\n",
"iter = 97\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9603\n",
"k = 0\n",
"\n",
"\n",
"iter = 98\n",
"iter = 98\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9702\n",
"k = 0\n",
"\n",
"\n",
"iter = 99\n",
"iter = 99\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9801\n",
"k = 0\n",
"\n",
"\n",
"iter = 100\n",
"iter = 100\n",
"res: [ 6.30826211e-03 1.27202498e-07 -1.07175457e-08 -1.83681405e-08]\n",
"res: [6.34461791e-03 4.87903407e-15 3.33091494e-15 6.31758417e-16]\n",
"err = 0.006308262114154177\n",
"mv = 9900\n"
"k = 0\n"
]
]
},
},
{
{
@ -803,7 +710,7 @@
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m x, \u001b[38;5;28miter\u001b[39m, mv \u001b[38;5;241m=\u001b[39m \u001b[43mAlgo4\u001b[49m\u001b[43m(\u001b[49m\u001b[43mPt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1e-6\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m x, \u001b[38;5;28miter\u001b[39m, mv \u001b[38;5;241m=\u001b[39m \u001b[43mAlgo4\u001b[49m\u001b[43m(\u001b[49m\u001b[43mPt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1e-6\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[5], line 101\u001b[0m, in \u001b[0;36mAlgo4\u001b[0;34m(Pt, v, m, a, tau, maxit, x)\u001b[0m\n\u001b[1;32m 98 \u001b[0m \u001b[38;5;28miter\u001b[39m \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 99\u001b[0m x \u001b[38;5;241m=\u001b[39m x_new\n\u001b[0;32m--> 101 \u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mMaximum number of iterations reached\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"Cell \u001b[0;32mIn[5], line 108\u001b[0m, in \u001b[0;36mAlgo4\u001b[0;34m(Pt, v, m, a, tau, maxit, x)\u001b[0m\n\u001b[1;32m 105 \u001b[0m \u001b[38;5;28miter\u001b[39m \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 106\u001b[0m x \u001b[38;5;241m=\u001b[39m x_new\n\u001b[0;32m--> 108 \u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mMaximum number of iterations reached\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"\u001b[0;31mException\u001b[0m: Maximum number of iterations reached"
"\u001b[0;31mException\u001b[0m: Maximum number of iterations reached"
]
]
}
}