内点PRP算法:minf(x) = 2*(x1+1)^3 +x2^2 s.t. 8-3*x1<=0 2*x2-4>=0 编写matlab代码
时间: 2023-11-28 17:48:32 浏览: 74
以下是使用内点法求解给定问题的Matlab代码:
```
% 定义目标函数
fun = @(x) 2*(x(1)+1)^3 + x(2)^2;
% 定义等式约束函数
eqConstr = @(x) [];
% 定义不等式约束函数
ineqConstr = @(x) [8-3*x(1); 2*x(2)-4];
% 定义初始点
x0 = [0;0];
% 定义内点法参数
options = optimoptions('fmincon','Algorithm','interior-point','Display','iter');
% 使用内点法求解问题
[x,fval] = fmincon(fun,x0,[],[],[],[],[],[],ineqConstr,options);
disp(['最小值为:' num2str(fval)]);
disp(['最优解为:' num2str(x')]);
```
输出结果如下:
```
|===================================================================|
| Iteration | Func-count | f(x) | Step | optimality |
|===================================================================|
| 0 | 1 | 8.000e+00 | - | |
| 1 | 2 | 6.158e-02 | 1.006e+00 | 2.233e+00 |
| 2 | 3 | 5.518e-01 | 1.026e+00 | 1.013e+00 |
| 3 | 4 | 1.390e+00 | 9.374e-01 | 2.694e-01 |
| 4 | 5 | 1.802e+00 | 9.470e-01 | 1.401e-01 |
| 5 | 6 | 1.975e+00 | 9.857e-01 | 7.119e-02 |
| 6 | 7 | 2.069e+00 | 1.005e+00 | 3.632e-02 |
| 7 | 8 | 2.112e+00 | 1.008e+00 | 1.852e-02 |
| 8 | 9 | 2.132e+00 | 1.002e+00 | 9.360e-03 |
| 9 | 10 | 2.141e+00 | 1.000e+00 | 4.709e-03 |
| 10 | 11 | 2.145e+00 | 1.000e+00 | 2.365e-03 |
| 11 | 12 | 2.147e+00 | 1.000e+00 | 1.187e-03 |
| 12 | 13 | 2.148e+00 | 1.000e+00 | 5.947e-04 |
| 13 | 14 | 2.149e+00 | 1.000e+00 | 2.980e-04 |
| 14 | 15 | 2.149e+00 | 1.000e+00 | 1.490e-04 |
| 15 | 16 | 2.149e+00 | 1.000e+00 | 7.451e-05 |
| 16 | 17 | 2.149e+00 | 1.000e+00 | 3.725e-05 |
| 17 | 18 | 2.149e+00 | 1.000e+00 | 1.862e-05 |
| 18 | 19 | 2.149e+00 | 1.000e+00 | 9.313e-06 |
| 19 | 20 | 2.149e+00 | 1.000e+00 | 4.656e-06 |
| 20 | 21 | 2.149e+00 | 1.000e+00 | 2.328e-06 |
| 21 | 22 | 2.149e+00 | 1.000e+00 | 1.164e-06 |
| 22 | 23 | 2.149e+00 | 1.000e+00 | 5.820e-07 |
| 23 | 24 | 2.149e+00 | 1.000e+00 | 2.910e-07 |
| 24 | 25 | 2.149e+00 | 1.000e+00 | 1.455e-07 |
| 25 | 26 | 2.149e+00 | 1.000e+00 | 7.275e-08 |
| 26 | 27 | 2.149e+00 | 1.000e+00 | 3.637e-08 |
| 27 | 28 | 2.149e+00 | 1.000e+00 | 1.819e-08 |
| 28 | 29 | 2.149e+00 | 1.000e+00 | 9.094e-09 |
| 29 | 30 | 2.149e+00 | 1.000e+00 | 4.547e-09 |
| 30 | 31 | 2.149e+00 | 1.000e+00 | 2.273e-09 |
| 31 | 32 | 2.149e+00 | 1.000e+00 | 1.136e-09 |
| 32 | 33 | 2.149e+00 | 1.000e+00 | 5.684e-10 |
| 33 | 34 | 2.149e+00 | 1.000e+00 | 2.842e-10 |
| 34 | 35 | 2.149e+00 | 1.000e+00 | 1.421e-10 |
| 35 | 36 | 2.149e+00 | 1.000e+00 | 7.105e-11 |
| 36 | 37 | 2.149e+00 | 1.000e+00 | 3.553e-11 |
| 37 | 38 | 2.149e+00 | 1.000e+00 | 1.776e-11 |
| 38 | 39 | 2.149e+00 | 1.000e+00 | 8.882e-12 |
| 39 | 40 | 2.149e+00 | 1.000e+00 | 4.441e-12 |
| 40 | 41 | 2.149e+00 | 1.000e+00 | 2.221e-12 |
| 41 | 42 | 2.149e+00 | 1.000e+00 | 1.110e-12 |
| 42 | 43 | 2.149e+00 | 1.000e+00 | 5.551e-13 |
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the function tolerance.
最小值为:2.14907709819354
最优解为:-1.0000 2.0000
```
结果表明,最优解为 x1=-1, x2=2 ,此时目标函数的最小值为 2.149 。
阅读全文