创建与目标函数对应的优化表达式
x=optimvar('x');
f=x^2/10 + exp(-exp(-x))
f=Nonlinear OptimizationExpression ((x.^2 https://ww2.mathworks.cn/help/optim/ug/ 10) + exp((-exp((-x)))))
从点 开始,找到最小化 的点。
x0=struct('x',0); prob=optimproblem('Objective',f); [sol,fval]=solve(prob,x0)
Solving problem using fminunc. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
sol=struct with fields:
x: -0.9595
fval=0.1656
如果 不是受支持的函数,您可以使用 对其进行转换。请参阅Supported Operations for Optimization Variables and Expressions和将非线性函数转换为优化表达式。
f=@(x)x^2/10 + exp(-exp(-x)); fun=fcn2optimexpr(f,x)
fun=Nonlinear OptimizationExpression ((x.^2 https://ww2.mathworks.cn/help/optim/ug/ 10) + exp((-exp((-x)))))
prob=optimproblem('Objective',fun);
[sol,fval]=solve(prob,x0)
Solving problem using fminunc. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
sol=struct with fields:
x: -0.9595
fval=0.1656
Copyright 2018–2020 The MathWorks, Inc.