matlab中rosenbrock函数的代码?? 150
matlab上能用的能用分全给你1378分都给你1楼您所说的代码该如何使用呢??具体把哪些打进去?不好意思我一点不会matlab...
matlab上能用的
能用分全给你
1378分都给你
1楼您所说的代码该如何使用呢??具体把哪些打进去?不好意思我一点不会matlab 展开
能用分全给你
1378分都给你
1楼您所说的代码该如何使用呢??具体把哪些打进去?不好意思我一点不会matlab 展开
3个回答
展开全部
首先申明,这个程序不是我写的,也是我以前在网上找到的(本科的时候看过,没太看懂,但是测试过了,可以运行的)。
这是完整的rosenbrock函数的代码,绝对可用:
function [f, df, ddf] = rosenbrock(x);
% rosenbrock.m This function returns the function value, partial derivatives
% and Hessian of the (general dimension) rosenbrock function, given by:
%
% f(x) = sum_{i=1:D-1} 100*(x(i+1) - x(i)^2)^2 + (1-x(i))^2
%
% where D is the dimension of x. The true minimum is 0 at x = (1 1 ... 1).
%
% Carl Edward Rasmussen, 2001-07-21.
D = length(x);
f = sum(100*(x(2:D)-x(1:D-1).^2).^2 + (1-x(1:D-1)).^2);
if nargout > 1
df = zeros(D, 1);
df(1:D-1) = - 400*x(1:D-1).*(x(2:D)-x(1:D-1).^2) - 2*(1-x(1:D-1));
df(2:D) = df(2:D) + 200*(x(2:D)-x(1:D-1).^2);
end
if nargout > 2
ddf = zeros(D,D);
ddf(1:D-1,1:D-1) = diag(-400*x(2:D) + 1200*x(1:D-1).^2 + 2);
ddf(2:D,2:D) = ddf(2:D,2:D) + 200*eye(D-1);
ddf = ddf - diag(400*x(1:D-1),1) - diag(400*x(1:D-1),-1);
end
比如说,你可以使用常用的多目标函数的优化来调用:
>> [x fx c] = minimize([0 1]', 'rosenbrock', 50)
Linesearch 1; Value 9.801010e-001
Linesearch 2; Value 7.711174e-001
Linesearch 3; Value 6.087456e-001
Linesearch 4; Value 4.170023e-001
Linesearch 5; Value 3.019709e-001
Linesearch 6; Value 2.622712e-001
Linesearch 7; Value 5.074002e-002
Linesearch 8; Value 4.360344e-002
Linesearch 9; Value 2.569778e-002
Linesearch 10; Value 9.313900e-003
Linesearch 11; Value 2.831055e-003
Linesearch 12; Value 6.570921e-004
Linesearch 13; Value 7.260670e-005
Linesearch 14; Value 2.660941e-007
Linesearch 15; Value 3.306084e-011
Linesearch 16; Value 1.640334e-012
Linesearch 17; Value 4.746897e-014
Linesearch 18; Value 6.733194e-020
Linesearch 19; Value 2.144528e-025
Linesearch 20; Value 1.343529e-030
Linesearch 21; Value 4.930381e-032
x =
1.0000
1.0000
fx =
101.0000
0.9801
0.7711
0.6087
0.4170
0.3020
0.2623
0.0507
0.0436
0.0257
0.0093
0.0028
0.0007
0.0001
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
c =
23
>>
minimize时多目标优化的函数,你应该不需要的。
这是完整的rosenbrock函数的代码,绝对可用:
function [f, df, ddf] = rosenbrock(x);
% rosenbrock.m This function returns the function value, partial derivatives
% and Hessian of the (general dimension) rosenbrock function, given by:
%
% f(x) = sum_{i=1:D-1} 100*(x(i+1) - x(i)^2)^2 + (1-x(i))^2
%
% where D is the dimension of x. The true minimum is 0 at x = (1 1 ... 1).
%
% Carl Edward Rasmussen, 2001-07-21.
D = length(x);
f = sum(100*(x(2:D)-x(1:D-1).^2).^2 + (1-x(1:D-1)).^2);
if nargout > 1
df = zeros(D, 1);
df(1:D-1) = - 400*x(1:D-1).*(x(2:D)-x(1:D-1).^2) - 2*(1-x(1:D-1));
df(2:D) = df(2:D) + 200*(x(2:D)-x(1:D-1).^2);
end
if nargout > 2
ddf = zeros(D,D);
ddf(1:D-1,1:D-1) = diag(-400*x(2:D) + 1200*x(1:D-1).^2 + 2);
ddf(2:D,2:D) = ddf(2:D,2:D) + 200*eye(D-1);
ddf = ddf - diag(400*x(1:D-1),1) - diag(400*x(1:D-1),-1);
end
比如说,你可以使用常用的多目标函数的优化来调用:
>> [x fx c] = minimize([0 1]', 'rosenbrock', 50)
Linesearch 1; Value 9.801010e-001
Linesearch 2; Value 7.711174e-001
Linesearch 3; Value 6.087456e-001
Linesearch 4; Value 4.170023e-001
Linesearch 5; Value 3.019709e-001
Linesearch 6; Value 2.622712e-001
Linesearch 7; Value 5.074002e-002
Linesearch 8; Value 4.360344e-002
Linesearch 9; Value 2.569778e-002
Linesearch 10; Value 9.313900e-003
Linesearch 11; Value 2.831055e-003
Linesearch 12; Value 6.570921e-004
Linesearch 13; Value 7.260670e-005
Linesearch 14; Value 2.660941e-007
Linesearch 15; Value 3.306084e-011
Linesearch 16; Value 1.640334e-012
Linesearch 17; Value 4.746897e-014
Linesearch 18; Value 6.733194e-020
Linesearch 19; Value 2.144528e-025
Linesearch 20; Value 1.343529e-030
Linesearch 21; Value 4.930381e-032
x =
1.0000
1.0000
fx =
101.0000
0.9801
0.7711
0.6087
0.4170
0.3020
0.2623
0.0507
0.0436
0.0257
0.0093
0.0028
0.0007
0.0001
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
c =
23
>>
minimize时多目标优化的函数,你应该不需要的。
展开全部
http://www.kyb.tuebingen.mpg.de/bs/people/carl/code/minimize/
http://www.nag.co.uk/industryarticles/usingtoolboxmatlab.asp
http://faculty.ucmerced.edu/mcarreira-perpinan/math519/2005-Spring/project2-templates/fcontours.m
Implicitly Constrained Optimization Problems:
http://www.caam.rice.edu/~heinken/software/matlab_impl_constr/
http://www.nag.co.uk/industryarticles/usingtoolboxmatlab.asp
http://faculty.ucmerced.edu/mcarreira-perpinan/math519/2005-Spring/project2-templates/fcontours.m
Implicitly Constrained Optimization Problems:
http://www.caam.rice.edu/~heinken/software/matlab_impl_constr/
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-04-02
展开全部
赋值一个初始的向量执行该函数。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询