Minimize banana function with steepest descent algorithm
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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));
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Chassis Systems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!