parameter values (2 , 2 , 2 ,4 )
%%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 %%%%%%%%%%%%%%%%%%%
Minimize f (X , X)-X,-AX2+ bx 12+ Cx x2+ dx , 2 2 Use any programing language of your preference ...
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...