The choice of step length is a very difficult topic in the optimization. Here, I use a common strategy:we consider a lot of different step length and choose the one which gets the smallest J (our target is to minimize j). And you can of couse consider other strategies.
The second question, you can just print(i) in the end to obtain the number of iterations…..
You may get some error. See my result. The J at n=0 should be large. But it should decreases quickly in a few steps and then decreases very slow.
The code printed all the result. You can use the first three rows to fill the blank.
The question requires that the norm of the gradient of J is less than 1e-6. The norm: we can use L1 norm, which is grad[0]+grad[1],
Of course you can also use the L2 norm, you can use sqrt( grad[0]^2+grad[1]^2)).
You can check the wiki for the norm of a vector.
Please read the question carefully! not J itself.
This is the process for a). For b), there is no process. Indeed, the result for a) is well-know. So, the question uses the term “normal equations”.
See the updated.
