問題描述:
有一組裝件由七個零件組成,這七個零件引數服從正態分佈
x1~n(0.1,(0.005/3) ^2);
x2~n(0.3,0.0052^2);
x3~n(0.1,(0.005/3)^2);
x4~n(0.1,0.0052^2);
x5~n(1.5,(0.225/3)^2);
x6~n(16,(0.8/3)^2);
x7~n(0.75,(0.0375/3)^2);
該組裝件的效能函式:
目標值是y0 = 1.5,偏離±0.1時,產品為次品,損失1000元;偏離±0.3時為廢品,損失9000元。
(1)計算生產一件該產品的損失期望值;
(2)以各零件引數的均值u為變數,波動範圍為20%,方差為固定值,試確定各零件的均值來優化產品效能。
1*第一問求解:
用normrnd建立七個服從正態分佈的隨機變數,對y進行大量實驗,統計其落在某區間的概率,以求得損失期望值。
syms k j n m
k=0;
n=0;
m=0;
for i=1:1000
x1 = normrnd(0.1,(0.005/3));
x2 = normrnd(0.3,0.005);
x3 = normrnd(0.1,(0.005/3));
x4 = normrnd(0.1,0.005);
x5 = normrnd(1.5,(0.225/3));
x6 = normrnd(16,(0.8/3));
x7 = normrnd(0.75,(0.0375/3));
y = 174.42*(x1/x5)*(x3/(x2-x1))^0.85*sqrt((1-2.62*(1-0.36*(x4/x2)^(-0.56))^(3/2)*(x4/x2)^1.16)/(x6*x7));
if(1.41.8||y==1.8||y<1.2||y==1.2)
m=m+1; %統計廢品個數
endendknm
j = (n*1000+m*9000)/1000 %損失
2*第二問求解
分別用fmincon和ga遺傳演算法求解,二者均可以設定所求變數的上下限和其滿足的約束函式;二者均需另外建立方法的**檔案,再在另一**檔案中呼叫;前者要給出變數初值,後者不用。
用fmincon求解
#fun.m#**檔案
function y0 = fun(x)
y1 = 'abs(174.42*(normrnd(x(1),(0.005/3))/normrnd(x(5),(0.225/3)))*(normrnd(x(3),(0.005/3))/(normrnd(x(2),0.005)-normrnd(x(1),(0.005/3))))^0.85*sqrt((1-2.62*(1-0.36*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^(-0.56))^(3/2)*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^1.16)/(normrnd(x(6),(0.8/3))*normrnd(x(7),(0.0375/3))))-1.5)';
y2 = '+abs(174.42*(normrnd(x(1),(0.005/3))/normrnd(x(5),(0.225/3)))*(normrnd(x(3),(0.005/3))/(normrnd(x(2),0.005)-normrnd(x(1),(0.005/3))))^0.85*sqrt((1-2.62*(1-0.36*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^(-0.56))^(3/2)*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^1.16)/(normrnd(x(6),(0.8/3))*normrnd(x(7),(0.0375/3))))-1.5)';
for i = 1:100
y1 = strcat(y1,y2); %前面y1,y2定義為字串,用strcat將y1,y2拼接起來,目的是使其求出的解更接近最優解
endy0 = eval(y1); %eval將字串轉化為命令
end
#fmincon_method#**檔案
syms k j n m
k=0;
n=0;
m=0;
x0 = [0.1;0.3;0.1;0.1;1.5;16;0.75]; %初值
lb = [0.08;0.24;0.08;0.08;1.2;12.8;0.6]; %變數下限
ub = [0.12;0.36;0.12;0.12;1.8;19.2;0.9]; %變數上限
fval = 150;
while (fval>100)
[x,fval] = fmincon(@fun,x0,,,,,lb,ub); %其中四個表示等式約束和不等式約束均為空,x是所求變數的數列,fval是#fun.m#中所求函式的「最優值」(可能只是區域性最優,甚至因為變數本身有隨機性而產生的錯誤結果)
endx
fval
for i=1:1000
x1 = normrnd(x(1),0.005/3);
x2 = normrnd(x(2),0.005);
x3 = normrnd(x(3),0.005/3);
x4 = normrnd(x(4),0.005);
x5 = normrnd(x(5),0.225/3);
x6 = normrnd(x(6),0.8/3);
x7 = normrnd(x(7),0.0375/3);
y = 174.42*(x1/x5)*(x3/(x2-x1))^0.85*sqrt((1-2.62*(1-0.36*(x4/x2)^(-0.56))^(3/2)*(x4/x2)^1.16)/(x6*x7));
if(1.41.8|y==1.8|y<1.2|y==1.2)
m=m+1; %統計廢品個數
endendknm
j = (n*1000+m*9000)/1000 %損失
用ga遺傳演算法求解#ga_fun.m#**檔案
function f = ga_fun(x)
y1 = 'abs(174.42*(normrnd(x(1),(0.005/3))/normrnd(x(5),(0.225/3)))*(normrnd(x(3),(0.005/3))/(normrnd(x(2),0.005)-normrnd(x(1),(0.005/3))))^0.85*sqrt((1-2.62*(1-0.36*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^(-0.56))^(3/2)*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^1.16)/(normrnd(x(6),(0.8/3))*normrnd(x(7),(0.0375/3))))-1.5)';
y2 = '+abs(174.42*(normrnd(x(1),(0.005/3))/normrnd(x(5),(0.225/3)))*(normrnd(x(3),(0.005/3))/(normrnd(x(2),0.005)-normrnd(x(1),(0.005/3))))^0.85*sqrt((1-2.62*(1-0.36*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^(-0.56))^(3/2)*(normrnd(x(4),0.005)/normrnd(x(2),0.005))^1.16)/(normrnd(x(6),(0.8/3))*normrnd(x(7),(0.0375/3))))-1.5)';
for i = 1:13
y1 = strcat(y1,y2);
endf = eval(y1);
end
#ga_method#**檔案
syms k j n m
k=0;
n=0;
m=0;
lb = [0.08;0.24;0.08;0.08;1.2;12.8;0.6];
ub = [0.12;0.36;0.12;0.12;1.8;19.2;0.9];
[x,fval,exitflag] = ga(@ga_fun,7,,,,,lb,ub); %7表示有七個變數
x fval
for i=1:1000
x1 = normrnd(x(1),0.005/3);
x2 = normrnd(x(2),0.005);
x3 = normrnd(x(3),0.005/3);
x4 = normrnd(x(4),0.005);
x5 = normrnd(x(5),0.225/3);
x6 = normrnd(x(6),0.8/3);
x7 = normrnd(x(7),0.0375/3);
y = 174.42*(x1/x5)*(x3/(x2-x1))^0.85*sqrt((1-2.62*(1-0.36*(x4/x2)^(-0.56))^(3/2)*(x4/x2)^1.16)/(x6*x7));
if(1.41.8|y==1.8|y<1.2|y==1.2)
m=m+1; %統計廢品個數
endendknm
j = (n*1000+m*9000)/1000 %損失
總結,用fmincon求解有一定隨機性,想獲得良好的優化引數有一定的運氣成分,用ga求解比較穩定,一般能取得較好的優化引數。 一日一結2012 5 2
今天去圖書館把作業系統概念借到了,期待很久,欣喜萬分。專業知識部分 今天主要學習了一下mfc六大關鍵技術,感覺講得不錯。主要的例子是以基於文件類的程式,感覺學到了東西。以前看孫新老師的書時是有點半知不解,看了這個資料讓我對mfc程式的內部有了更深一層的理解。課外知識部分 看完10000小時code ...
一日一結2012 5 6
今天天氣很熱,感覺已經進入夏天。看了galaxy 3 效能評測,不錯。專業知識部分 今天看了作業系統概念的虛擬記憶體,了解了虛擬記憶體的概念和原理,虛擬記憶體這種記憶體管理技術允許執行程序不必完全在記憶體中。而且,虛擬記憶體將記憶體抽象成乙個巨大的 統一的儲存陣列,進而將使用者看到的邏輯記憶體和物理...
一日小結(04 19)
聽了老賀的建議,來到csdn上來寫部落格 今天stm32是一點都沒有學,原本計畫著晚上7點開始學的,沒成想3d印表機出問題了 沒料打了乙個半成品 配合月哥搗鼓了半天才把黑色的料換好,不過雖然stm32上沒有比昨天更進一步,但還是學到了挺多東西的 今天學習了指標中的void指標和null指標 void...