usingLinearAlgebrausingForwardDiff""" Solve by Newton's algorithm the optimization problem Min f(x) Case where f is a function from R^n to R"""functionalgo_Newton(f,x0::Vector{<:Real};AbsTol=abs(eps()), RelTol =abs(eps()), ε=0.01, nbit_max =0)# to complete# flag = 0 if the program stop on the first criteria# flag = 2 if the program stop on the second criteria# ...return xₖ, flag, fₖ, ∇fₖ , k end
algo_Newton (generic function with 1 method)
Code
include("assets/julia/MyOptims.jl")A = [10 ; 09/2]b = [0,0]; c=0.f1(x) =0.5*x'*A*x + b'*x +cx0 = [1000,-20]println("Results for Newton on f1 : ", algo_Newton(f1,x0))println("eigen value of 0.5(A^T+A) = ", 0.5*eigen(A'+A).values)usingPlots;x=range(-10,stop=10,length=100)y=range(-10,stop=10,length=100)f11(x,y) =f1([x,y])p1 =plot(x,y,f11,st=:contourf)A = [-10 ; 03]f2(x) =0.5*x'*A*x + b'*x +cprintln("Results for Newton on f2 : ", algo_Newton(f2,x0))println("eigen value of 0.5(A^T+A) = ", 0.5*eigen(A'+A).values)f21(x,y) =f1([x,y])p2 =plot(x,y,f21,st=:contourf)# Rosenbrock functionx=range(-1.5,stop=2,length=100)y=range(-0.5,stop=3.,length=100)f3(x) = (1-x[1])^2+100*(x[2]-x[1]^2)^2f31(x,y) =f3([x,y])p3 =plot(x,y,f31,st=:contourf)x0 = [1.1,1.2]println("Results for Newton on f3 : ", algo_Newton(f3,[1.1,1.2]))println("Results for Newton on f3 : ", algo_Newton(f3,[3.,0.]))plot(p1,p2,p3)
Results for Newton on f1 : ([0.0, 0.0], 0, 0.0, [0.0, 0.0], 1)
eigen value of 0.5(A^T+A) = [1.0, 4.5]
Results for Newton on f2 : ([0.0, 0.0], 0, 0.0, [0.0, 0.0], 1)
eigen value of 0.5(A^T+A) = [-1.0, 3.0]
Results for Newton on f3 : ([1.0, 1.0], 0, 0.0, [-0.0, 0.0], 7)
Results for Newton on f3 : ([1.0, 1.0], 0, 0.0, [-0.0, 0.0], 5)
Complete the steepest_descent_quad function and execute the following sript and explain why the Newton’s algorithm converge in one iteration.
A = [1.0 0.0; 0.0 9.0]
b = [-4.0, -18.0]
n= 5
Result with Newton's algorithm :
xsol = [2.0, 1.0]
flag = 0
fsol = 0.0
∇f_xsol = [0.0, 0.0]
nb_iter = 1
Linear search: Armijo’s condition and backtraking
Let \(x_k\) the current iterate and \(d_k=-\nabla f(x_k)\). We note \(g_k(\alpha)=f(x_k+\alpha d_k)\) We want to find an \(\alpha>0\) such that we have a sufficient decay of the function \(g_k\), i.e. which verify the Armijo’s condition : \(g_f(\alpha)=f(x_k+\alpha d_k)\le f_k+c_1\alpha\nabla f_k^Td_k=\tilde{g}_f(\alpha)\)