% 定义目标函数
f = @(x) 4*(x(2)-x(1))^2 + (x(2)-4)^2;

% 定义初始点
x0 = [1, 1];

% 调用 fminsearch 函数进行优化
[x, fval] = fminsearch(f, x0);

% 输出结果
disp(['最小值为:', num2str(fval)]);
disp(['最优解为:x1 = ', num2str(x(1)), ', x2 = ', num2str(x(2))]);
使用fminsearch求 min f=4x2-x12+x2-42 选择初始点x011写出matlab代码

原文地址: http://www.cveoy.top/t/topic/fqYJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录