[討論] 請教一下會使用fmincon的高手一點簡單ꨠ…已回收
噁死胎偷,新手使用這個指令..不對的話請鞭 囧>
我的目標函數:
---------------------------------------------------
function f = myfun3_1(x);
% 目標函數
a1 = 1;
a2 = 1;
p = 0.7;
people = 40;
money = 0.0789;
delta_P = p*people*money;
w = 0.0002;
f = (a1*w*(x(2)^3)*x(3)) + (a2*x(3)*delta_P);
----------------------------------------------------
然後是我的限制式:
function [c,ceq] = mycon3_1(x);
% 限制式
V = 10*5*3;
c_initial = 1000*10^-6;
c_out = 500*10^-6;
P = 40;
AP= 0.023/3600;
G = AP*P;
c = [];
ceq =
x(1)-((c_out+(G/x(2)))*(1-exp((-x(2)/V)*x(3)))-c_initial*exp((-x(2)/V)*x(3)));
-----------------------------------------------------
執行:
clear all
clc
x0 = [1000 0 1];
lb = [600*10^-6 0.3 1];
ub = [800*10^-6 0.5 99999];
[x,fval] = fmincon('myfun3_1',x0,[],[],[],[],lb,ub,'mycon3_1')
-----------------------------------------------------
然後出來的結果為:
Warning: Large-scale (trust region) method does not currently solve this type
of problem,
switching to medium-scale (line search).
> In fmincon at 260
In test_CO2 at 6
Optimization terminated: first-order optimality measure less than
options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1 2
x =
0.0006 0.5000 476.2737
fval =
1.0522e+003
------------------------------------------------------------------------------
問題來了..新手小弟我不曉得這樣跑出來的結果到底是不是最佳解..囧
因為出現了Warning以及Optimization terminated的字眼,我想請教高手是否知道我的
問題在哪邊.. 囧"> 感謝~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 120.126.8.117
推
01/25 13:05, , 1F
01/25 13:05, 1F
嗯,那不好意思再請問一下,改參數是指說我設定的所有參數都有問題而解出來的值
怪怪的,還是說只有部分的參數需要更改而已? 另外想請教 x0 的設置是不是也會讓
答案有所不一樣?
※ 編輯: bawpee 來自: 120.126.8.117 (01/25 13:41)
推
01/25 14:55, , 2F
01/25 14:55, 2F
→
01/25 14:56, , 3F
01/25 14:56, 3F
→
01/25 15:04, , 4F
01/25 15:04, 4F
→
01/25 15:05, , 5F
01/25 15:05, 5F
→
01/25 15:05, , 6F
01/25 15:05, 6F
嗯,你說的方法我之前就有試過了,還是會有一樣的問題,我在其他論壇看到有這種問題
的人都是這樣下去試也是會出現Warning,我是用7.0版的,聽說2008b就沒有這個問題吧?
→
01/25 21:23, , 7F
01/25 21:23, 7F
→
01/25 21:26, , 8F
01/25 21:26, 8F
嗯~因為是新手,所以真的很抱歉不太清楚您的敘述 0.0"
※ 編輯: bawpee 來自: 118.160.144.169 (01/26 01:20)
→
01/26 20:20, , 9F
01/26 20:20, 9F
嗯,我有依照您的方式下去try了~ 他顯示是 " 1 " 所以代表它有收斂?
※ 編輯: bawpee 來自: 118.168.167.94 (01/26 22:00)
→
01/26 23:38, , 10F
01/26 23:38, 10F
→
01/26 23:39, , 11F
01/26 23:39, 11F
→
01/26 23:40, , 12F
01/26 23:40, 12F
→
01/26 23:42, , 13F
01/26 23:42, 13F
感謝指教! 這就是沒有學長問然後得到貴人相助的感覺 T_T
※ 編輯: bawpee 來自: 118.168.167.94 (01/27 01:11)
推
01/28 15:40, , 14F
01/28 15:40, 14F