错误。优化与分析的麻绳

1视图(30天)
下面的程序是不工作。
这是生成以下错误:
错误使用梯度(第6行)
足够的输入参数。
错误在rosenbrockwithgradhess(第7行)
g =梯度(x);
错误在Optimization_With_Analytic_Hessian > @ (x) rosenbrockwithgradhess (x,
双(a),双(b))(27)行
[x, fval eflag,输出]= fminunc (@ (x) rosenbrockwithgradhess (x,
双(a),双(b)), x0,选项);
错误在fminunc(第280行)
[f,研究生,赫斯]=函数宏指令(funfcn {3}, x,变长度输入宗量{:});
错误在Optimization_With_Analytic_Hessian(27)行
[x, fval eflag,输出]= fminunc (@ (x) rosenbrockwithgradhess (x,
双(a),双(b)), x0,选项);
错误在主(57)行
[x, fval eflag, iter fcount] =
Optimization_With_Analytic_Hessian (starting_point);
引起的由:
失败在最初的用户提供的目标函数评价。
FMINUNC不能继续下去。
Optimization_With_Analytic_Hessian.m
函数[x, fval eflag, iter fcount] =
Optimization_With_Analytic_Hessian (start_point)
%分配起点
x0 = start_point;
%读系数a、b
多项式系数=负载(“coeff.txt”);
一个=多项式系数(1);
b =多项式系数(2);
%的选项设置
选择= optimoptions (“fminunc”,
“显示”,“关闭”,
“OutputFcn”@bananaout,
“算法”,“信赖域”,
“GradObj”,“上”,
“海赛”,“上”);
%调用fminunc
[x, fval eflag,输出]= fminunc (@ (x) rosenbrockwithgradhess (x,
双(a),双(b)), x0,选项);
iter = output.iterations;
fcount = output.funcCount;
%绘制窗口标题
标题“优化与分析黑森…”
disp (“Optimization_With_Analytic_Hessian…”);
结束
相关的源代码:
函数[f, g, h] = rosenbrockwithgradhess (x, a, b)
% f计算目标
f =。(x, a, b);
%梯度要求
如果nargout > 1
g =梯度(x);
结束
%黑森所需
如果nargout > 2
h =黑森(x);
结束
结束
rosenbrock.m
函数=。(x, a, b)
xx = x (1);
yy = x (2);
= (1 - xx + a) ^ 2 + 100 * (yy - b - (xx-a) ^ 2) ^ 2;
结束
gradient.m
函数=梯度(coord, a, b)
x = coord (1);
y = coord (2);
= (2 * (-200 * (- x) * (^ 2 - 2 * * x + b + x ^ 2 - y) - a + x - 1);
200 * (- (- x) ^ 2 - b + y)];
结束
hessian.m
函数=黑森(coord, a, b)
x = coord (1);
y = coord (2);
= 400 * (200 * (ax) ^ 2 + 200 * b - 200 * y + 1);
结束
main.m
函数main ()
%初始数据
points_count = 4;
coeff_file_name =“coeff.txt”;
start_points_file_name =“data.txt”;
file_write_mode =' w ';
一个= gen_const ();%的整数
b = gen_const ();%的整数
%系数写入一个文件
write_to_file (coeff_file_name [a, b], file_write_mode)
%生成随机点4
m = gen_points (a, b, points_count);
%写点到一个文件
write_to_file (start_points_file_name, m, file_write_mode);
%从文件加载点
点=负载(start_points_file_name);
plot_ban ();
%迭代优化的点和使用它们
我= 1:points_count
starting_point =点(我:);
如果我= = 1
file_write_mode =' w ';
其他的
file_write_mode =“一个”;
结束
%的优化与分析的麻绳
[x, fval eflag, iter fcount] =
Optimization_With_Analytic_Hessian (starting_point);
write_to_file (“Optimization_With_Analytic_Hessian.txt”,
[a, b, starting_point, x, fval, eflag, iter, fcount], file_write_mode);
结束
结束

接受的答案

沃尔特·罗伯森
沃尔特·罗伯森 2017年1月5日
你rosenbeckwitgradhess例程接收a和b作为参数gradient.m但并不是通过他们

更多的答案(0)

类别

找到更多的在和迭代解算器输出显示帮助中心文件交换

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!