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…..

 

 

 

gradient

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.

gradient

gradient

Reminder
OK
作业代写,代写作业,作业辅导,辅导作业,作业问答,美国作业代写,留学生作业,留学生作业代写,数学作业,数学作业代写,统计作业代写,物理作业代写,金融作业代写,大学作业辅导 Keywords: 作业代写 代写作业 作业辅导 辅导作业 作业问答 美国作业代写 留学生作业 留学生作业代写 数学作业 数学作业代写 统计作业代写 物理作业代写 金融作业代写 大学作业辅导