?? variable_rotation.m
字號:
function [min,solvec,stepnum]=variable_rotation(str,ini,err)
% File name:variable_rotation.m
% Author:Yan Anxin
% ID number:081810
% Date:finished on 2008.11.18
% Description:
% Here defines a function,to solve the multivariate unconstrained optimization problems by variable-rotation-method
% In the syntax [min,solvec,stepnum]=variable_rotation(str,ini,err),
% str----input,means the expression of objective function
% ini----input,sets the starting point to ini
% err----input,sets admissible error
% min=variable_rotation(str,ini,err) attempts to find min, i.e. the minimum of objective function
% [min,solvec]=variable_rotation(str,ini,err) returns solvec, i.e. the minimum point
% [min,solvec,stepnum]=variable_rotation(str,ini,err) returns stepnum, i.e. the times of iterative
n=length(ini); %gets the number of variables
k=1;stepnum=0;x(:,k)=ini;
syms lam %defines searching step----lam
while 1
for t=1:n
g=x(t,k)+lam;
f=str;
for p=1:n
s=sym(['x' num2str(p)]);
if t==p
f=subs(f,s,g);
else
f=subs(f,s,x(p,k));
end
end
f1=diff(f,lam);
lamb=solve(f1,lam); %gets the best step
x(:,k+1)=x(:,k);x(t,k+1)=x(t,k+1)+lamb;
k=k+1;stepnum=stepnum+1;
end
if norm(x(:,k)-x(:,1))<=err,break,end %halts cycle if meeting the requirements of error
x(:,1)=x(:,k);
k=1;
end
solvec=x(:,k);
min=minval(str,solvec); %calls the function minval(str,solvec) to obtain the minimum value
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -