联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> javajava

日期:2020-02-09 10:29

MECH203 – Mathematical and Computational Tools for Mechanical Engineers II

MECH 203

Jupyter Notebook Assignment

Optimization

PART 2 – Unconstrained optimization

Let’s practice our coding skills and check if we have a good handle on the basics of local optimization!

We’ll do this by writing our own steepest descent solver.

Section A- Find the minimum of the following function:

??(??, ??) =12??2 + 5??2 +23(?? ? 2)4 + 8(?? + 1)41) Define the function and its analytical gradient in Jupyter notebook. ( 2 marks)

2) Implement a steepest gradient algorithm. Use x0 = 10, y0 = 20 as starting points. You can consider

that the algorithm has converged to a solution if f(x,y) is within 0.0001 of its optimal value. (8 marks)

3) Plot the values of f(x,y)—or log(f(x,y))—x and y at each step during

optimization (2 marks).

(PS: this function is positive in all points. You can draw a

contour plot with “ax.contour” of the log of this function, which

will illustrate that the method is following the gradient. It’s OK

if you don’t, you can plot in any way that makes sense to you;

but it makes for a cool plot. The advantage of the log is that it

makes the x**4 function increase in value less quickly, which facilitates plotting. Note

that this example is incomplete: you should insert better labels and legends.)

4) Instead of using your own method, use the CG and BFGS algorithms available in the

SciPy.optimize.minimize module. (tip: you can input the analytical gradient that you

implemented above using “jac=”; this will make the calculation much more efficient than having

the computer perform numerical derivatives.) Use x0 = 10, y0 = 20 as starting points. (6 marks)

5) Which method provided the best results, in your opinion? Explain your reasoning (2 marks)

Section B- Minimize the following function instead:

1) Define the function and its analytical gradient in Jupyter notebook. ( 2 marks)

2) Implement a steepest gradient algorithm. Use x0 = 2, y0 = 20 as starting points. You can consider

that the algorithm has converged to a solution if f(x,y) is within 0.0001 of its optimal value. (4

marks).

3) BONUS (2 marks): Plot the value of f(x,y), x, and y. For example:

MECH203 – Mathematical and Computational Tools for Mechanical Engineers II

(you should insert better labels and legends.)

4) Use the CG and BFGS algorithms available in the SciPy.optimize.minimize module. Use x0 = 2,

y0 = 20 as starting points. (4 marks).

5) How many minima does this function have? (2 marks)

6) Can the computer find them all? (2 marks)

7) Are they local or global? (2 marks)

Section C- Explain in about half-a-page (400 words) how the CG and BFGS algorithms

function. Feel free to use equations and graphs. (4 marks)


版权所有:留学生程序网 2020 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。