Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Minimize the function f(x) = 100 [(x_2, - x_1^2)^2 +(1 -x_i)^2] using the steepe

ID: 1717014 • Letter: M

Question

Minimize the function f(x) = 100 [(x_2, - x_1^2)^2 +(1 -x_i)^2] using the steepest descent method. You are encouraged to write appropriate Matlab code to solve this problem.

Explanation / Answer

disp('Would you like to clear your workspace memory and command screen?'); z=input('To do so enter 1, any other number to continue:'); if z==1 clc;clear end choice=input('To do a maximization enter 1, for minimization enter 2:');a=2; while a==2 if choice~=1&&choice~=2 disp('Wrong input!');a=2; choice=input('To do a maximization enter 1, for minimization enter 2:'); else a=1; end end a=2;mark=0;flag=0;count=0;syms b;u=[];warning off all try while a==2 n=floor(input('Enter the dimension of function:')); if neps fprintf(' The error tolerance you provided has not been achieved yet '); flag=input('To terminate enter 1, any other number to continue:'); end if flag==1 hes=k; for i=1:n hes=subs(hes,['x' num2str(i)],X(i)); end fprintf(' ..........Result........... ') if length(find(eig(hes)>0))==length(eig(hes)) disp('At the present point the function is convex so it may be a local minimum!'); elseif length(find(eig(hes)0 steplength=t(i);break end end end if steplength==0 for i=1:length(t) if isreal(t(i))==1 if t(i)>0 steplength=t(i);break end end end end if steplength==0 steplength=0.001; end end funct=f; for i=1:n funct=subs(funct,['x' num2str(i)],X(i)); end disp('Functional value at present='); if choice==1 disp(-funct) elseif choice==2 disp(funct) end disp('Step size taken=');disp(steplength); X=X-steplength*grad; if count>100 disp('You already have performed 100 iterations and it seems that no extremum of the function exists!'); flag=input('It is recommended that you terminate the procedure, to do so enter 1, any other number to continue:'); end end end