Question: In Matlab: Demo code: clc %clear command window clf %clear current figure clear all %clear workspace variables format compact %show less whitespace format long %show

In Matlab:

In Matlab: Demo code: clc %clear command window clf %clear current figure

Demo code:

clc %clear command window clf %clear current figure clear all %clear workspace variables format compact %show less whitespace format long %show accuracy with more digits tolg=1e-9; %tolerance on the gradient tolx=1e-8; %tolerance on the value of x

Problem = 2 %1-4 z=[2.5;2.5;2.5]; Algorithm='D'; % N - Newton's Method % D - Diagonal Scaled Steepest Descent % S - Steepest Descent % B - BFGS switch Problem case 1 A=[0.339,-0.033,0.066;-0.033,1.0,0.199;0.066,0.199,0.704]; b=[1.017;2.1;1.3]; f=@(x) 0.5*x'*A*x-b'*x; g=@(x) A*x-b; H=@(x) A; M=@(x) diag(A); case 2 A=[0.011,-0.001,0.01;-0.001,1.0,0.2;0.01,0.2,0.14]; b=[0.041;2.197;0.57]; f=@(x) 0.5*x'*A*x-b'*x; g=@(x) A*x-b; H=@(x) A; M=@(x) diag(A); case 3 A=[0.339,-0.033,0.066;-0.033,1.0,0.199;0.066,0.199,0.704]; b=[2.985;3.902;2.094]; f=@(x) 0.5*(x.^2)'*A*(x.^2)-b'*(x.^2); g=@(x) 2*(A*(x.^2)-b).*x; H=@(x) diag(2*A*(x.^2))+4*(x*x').*A-2*diag(b); M=@(x) 2*A*(x.^2)+4*x.^2.*diag(A)-2*b; case 4 A=[0.011,-0.001,0.01;-0.001,1.0,0.2;0.01,0.2,0.14]; b=[0.105;4.191;1.03]; f=@(x) 0.5*(x.^2)'*A*(x.^2)-b'*(x.^2); g=@(x) 2*(A*(x.^2)-b).*x; H=@(x) diag(2*A*(x.^2))+4*(x*x').*A-2*diag(b); M=@(x) 2*A*(x.^2)+4*x.^2.*diag(A)-2*b; end

fc=0; %counter for function evaluations gc=0; %counter for gradient evaluations hc=0; %counter for hessian evaluations dhc=0; %counter for hessian diagonals evaluations

%Calculate Initial State switch Algorithm case 'N' fk=f(z); fc=fc+1; gk=g(z); gc=gc+1; Hk=H(z); hc=hc+1; case 'S' fk=f(z); fc=fc+1; gk=g(z); gc=gc+1; case 'D' fk=f(z); fc=fc+1; gk=g(z); gc=gc+1; Mk=M(z); dhc=dhc+1; end

for k=1:10000 switch Algorithm case 'N' %Calculate Descent Direction d=-Hk\gk; %Calculate Descent Step slope=gk'*d; [zn,cn]=Armijo(z(:,k),d,fk,f,slope,0.5,0.1,1.0); z(:,k+1)=zn; fc=fc+cn; if norm(z(:,k+1)-z(:,k)) (1) Using the provided code (either directly or as a reference for your own code), write code to solve the four optimization problems given in the code by steepest descent using an Armijo step with s=1,=0.1, =0.5. You much keep an accurate count of the number of iterations used, the number of primary function evaluations performed, and the number of gradient calculation performed. Start at (2.5,2.5,2.5) and you are given that the solution to each of the four problems is (3,2,1). Be sure to have your code stop if the gradient gets too small or if the change in iterate is too small (see sample code). Use your code to complete the following table

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!