Help me with finding the minimum of one dimensional convex function using numerical gradient method

1 view (last 30 days)
Hi, I have to write a code for finding the minimum of one dimensional convex function using numerical gradinet method. So far I have:
if
% code
e % starts from this point
function ebo
clc
x0=2
E=1e-6
k=0.1
X1=x0
[F,g]=fun(X1)
X2=X1-sign(g)*k
[F2,g2]=fun(X2)
i=0;
while g*g2>0
i=i+1
[F,g]=fun(X1);
X2=X1-2^i*sign(g)*k;
X1=X2
[F2,g2]=fun(X2);
end
disp(X2);
disp(fun(X2));
function [F,g]=fun(x)
F=2*x^2+3;
g=4*x;
Im stuck, the gradient always shows me 0. I really need help, could you please correct mine code or help me.

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!