Question

Minimize f (X , X)-X,-AX2+ bx 12+ Cx x2+ dx , 2 2 Use any programing language of your preference .Use constant lambda . Run o

parameter values (2 , 2 , 2 ,4 )

. Minimize f (X X2)-X-AX2 + bx 2+ cx x 2+ . Use any programing language of your preference .Use constant lambda . Run optimiz

Minimize f (X , X)-X,-AX2+ bx 12+ Cx x2+ dx , 2 2 Use any programing language of your preference .Use constant lambda . Run optimization for three different starting points . Draw chart Optimality gap vs iterations
. Minimize f (X X2)-X-AX2 + bx 2+ cx x 2+ . Use any programing language of your preference .Use constant lambda . Run optimization for three different starting points . Draw chart Optimality gap vs iterations . You can use Wolframalpha to explore function Vary values of lambda Draw chart lambda vs number of iterations . .
0 0
Add a comment Improve this question Transcribed image text
Answer #1


SMatlab code for Gradient Descent method clear all close all functions for which minimum have to find fprintf( Displaying thefunction [xx val,error 1-steepest_descent (f, xx,l) % f(x,y) is the function for finding minima % x is the initial guess % isFor 1-0.1947 convergrnce in iteration count is 14 For I-0.2079 convergrnce in iteration count is 13. For 1-0.2211 convergrnce

%%Matlab code for Gradient Descent method
clear all
close all

%functions for which minimum have to find
f=@(x,y) x-2*y+2*x^2+2*x*y^2+4*y^2;

fprintf('Displaying the function f(x,y)\n')
disp(f)

l=0.1;        %set lambda value
xx=[2;1];      %set starting value
[xx_val,error]=steepest_descent(f,xx,l);

%minimum value using steepest descent for initial guess [2,2]
fprintf('\nminimum value using steepest descent for initial guess [%f,%f] is.\n',xx(1),xx(2))
fprintf('x1=%f; x2=%f\n',xx_val(1),xx_val(2))

l=0.1;        %set lambda value
xx=[1;2];      %set starting value
[xx_val,error]=steepest_descent(f,xx,l);

%minimum value using steepest descent for initial guess [2,2]
fprintf('\nminimum value using steepest descent for initial guess [%f,%f] is.\n',xx(1),xx(2))
fprintf('x1=%f; x2=%f\n',xx_val(1),xx_val(2))

l=0.1;        %set lambda value
xx=[2;2];      %set starting value
[xx_val,error]=steepest_descent(f,xx,l);

%minimum value using steepest descent for initial guess [2,2]
fprintf('\nminimum value using steepest descent for initial guess [%f,%f] is.\n',xx(1),xx(2))
fprintf('x1=%f; x2=%f\n\n',xx_val(1),xx_val(2))

%Loop for different lambda value and iteration count
ll=linspace(0.05,0.3,20);
for i=1:length(ll)
  
    l=ll(i);        %set lambda value
    xx=[2;2];      %set starting value
    [xx_val,error]=steepest_descent(f,xx,l);
    it_cnt(i)=length(error);
    fprintf('\tFor l=%2.4f convergrnce in iteration count is %d.\n',l,it_cnt(i))
  
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function for steepest descent method
function [xx_val,error]=steepest_descent(f,xx,l)
    % f(x,y) is the function for finding minima
    % xx is the initial guess
    % l is lambda value

    n=0;            %initialize iteration counter
    eps=1;          %initialize error
    syms x y
    %finding gradient
    f_x(x,y)=diff(f,x);
    f_y(x,y)=diff(f,y);

    %Computation loop
    while eps>1e-10 && n<500
        gradf=double([f_x(xx(1),xx(2));f_y(xx(1),xx(2))]); %gradf(x)
        yy=double(xx-l*gradf);                             %iterate
        n=n+1;
        eps=norm(xx-yy);                                    %counter+1
        error(n)=eps;
        xx=yy;                                             %update x

    end
    xx_val=xx;
end

%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Minimize f (X , X)-X,-AX2+ bx 12+ Cx x2+ dx , 2 2 Use any programing language of your preference ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. Let f(x) = ax2 +bx+c, where a > 0. Prove that the secant method for...

    5. Let f(x) = ax2 +bx+c, where a > 0. Prove that the secant method for minimization will terminate in exactly one iteration for any initial points Xo, X1, provided that x1 + xo: 6. Consider the sequence {x(k)} given by i. Write down the value of the limit of {x(k)}. ii. Find the order of convergence of {x(k)}. 7. Consider the function f(x) = x4 – 14x3 + 60x2 – 70x in the interval (0, 2). Use the bisection...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT