How can I use my own function to optimize using fminunc?
4 ビュー (過去 30 日間)
古いコメントを表示
Hi Can anybody help me solving my problem? I have a function in Matlab with two variables x1 and x2 and I wanna optimize my function and find the optimal value of x1 and x2 how can I use fminunc? this is may function :
function f=optim(x)
%%%%%x1 hlow for com 1, x2 for interval
%tau=5;
%H2=0.00125;
H1=0.000125;
CI=5800;
Cp=30000;
Cr=20000;
for j=2:10 % number of intervals
t1(j)=j*x2;
t2(j)=(j-1)*x2;
Inspcost1(j)=MyF(x1,t1(j));
Inspcost2(j)=MyF(x1,t2(j));
Inspcostall(j)=j.*abs((Inspcost2(j)-Inspcost1(j)));
end
Inspcost=CI*sum(Inspcostall(j))
f=Inspecost;
(MyF is another function) I don't know how to use matlab to optimize this?
0 件のコメント
採用された回答
Star Strider
2017 年 11 月 7 日
In the optimization routines, the parameters you want to optimise have to be in a single vector. In this instance, simply change them to subscripted veriables, ‘x(1)’ and ‘x(2)’:
t1(j)=j*x(2);
t2(j)=(j-1)*x(2);
Inspcost1(j)=MyF(x(1),t1(j));
Inspcost2(j)=MyF(x(1),t2(j));
3 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!