Лаба по ВычМ
.docКозловская К.В., гр. 042801.
«Оптимизация. Метод Гаусса-Зейделя»
-
Исследуемая функция: .
-
Код программы:
function GaZe (h,E,x1,x2) %h-step; E-error; x1,x2-init. coord.
x0=[x1 x2]; %starting point
d1=[1 0]; d2=[0 1]; %direction vectors
x=x0; %moving to starting point
while h>E
while 1 %min. along d1
if F(x+h*d1)<F(x)
x=x+h*d1;
F1=F(x);
elseif F(x-h*d1)<F(x)
x=x-h*d1;
F1=F(x);
else break;
end;
end;
while 1 %min. along d2
if F(x+h*d2)<F(x)
x=x+h*d2;
F1=F(x);
elseif F(x-h*d2)<F(x)
x=x-h*d2;
F1=F(x);
else break;
end;
end;
h=h/2;
end;
Xmin=x
Fmin=F1
end
-
m-файл с описанием функции :
function F=F(x)
F=3*x(1)*x(1)-4*x(2);
return
-
проверка программы: