Minimize banana function with steepest descent algorithm

18 Ansichten (letzte 30 Tage)
Mohamadmahdi Amirloo
Mohamadmahdi Amirloo am 26 Jan. 2021
I write this code to minimize banana function but its not working.can any body help me please?
clear;clc;
banana=@ (x,y) (100*(y-x^2)^2+(1-x)^2); x0=100; y0=50;
dx=0.001; dy=0.001;
error=0.0001;
g=[inf;inf];
number_of_iteration=0; grad_x=@(x,y) (300*x^2-400*x*y+2*x-2); grad_y=@(x,y) (200*(y-x^2)); banana0=banana(x0,y0); grad_x0=grad_x(x0,y0); grad_y0=grad_y(x0,y0);
while norm(g)>error
gx=grad_x(x0,y0);
gy=grad_y(x0,y0);
alpha_x=gx*dx;
alpha_y=gy*dy;
g=[gx;gy];
x0=x0-alpha_x;
y0=y0-alpha_y;
number_of_iteration=number_of_iteration+1;
end fprintf('number of iterations until convergence is =%3i\n',(number_of_iteration));

Antworten (0)

Kategorien

Mehr zu Chassis Systems finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by