用fmincon求解即可:
>> x=fmincon(@(x)sin(x(1))+sin(x(2)),[1 1],[],[],[1 1],3,[0 0])
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
1.5000 1.5000
也可以绘图加以验证:
ezcontour(@(x1,x2)sin(x1)+sin(x2),[0 3])
hold on
ezplot('x1+x2=3')
x=fmincon(@(x)sin(x(1))+sin(x(2)),[1 1],[],[],[1 1],3,[0 0]);
plot(x(1),x(2),'ro')
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/6d81800a19d8bc3eda4c0faf848ba61ea8d3450a?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)