How to create an objective function c(t) to use fminserch , struggle with the summatoin , i used the following code for the optimization but it doesn't seem to work
1 回表示 (過去 30 日間)
古いコメントを表示
function i= cout(cc,cp,crg,alpha,delta,eta,rho,beta,K,T )
cc=15000;
cp=10000;
crg=200000;
rho=0.5;
eta=56.9;
beta=2.6;
alpha=1.63;
delta=0.015;
s=0;
T=1:1:600;
K=20;
ct=[];Y=[];X=[];
for K=20
s=s+((((K-((K-1).*rho))/eta).^beta-(((K-1)-(K-1).*rho)/eta).^beta)-((((K-1)/eta).^beta).*(beta*delta))).*alpha
ct=[ct;((crg+cp*(K-1))/(K))*(T.^(-1))+((cc*s)*(T.^(beta-1)))/(K)]
X=[X,min(ct)];
Y=min(ct);
end
[T,K]=meshgrid(1:1:600,20);
figure
plot(T,ct)
X;
Y;
i=find(X==min(X))
j=find(Y==min(Y))
4 件のコメント
Torsten
2022 年 8 月 28 日
K is a summation index in your notation - so it's unclear what you mean by "tryin to find T and K that minimize C(T)".
And what about the summation index K in the denominator of C(T) ?
回答 (1 件)
Alan Stevens
2022 年 8 月 30 日
Do you mean something like this:
KT0 = [1, 10]; % initial guesses
[KT, C] = fminsearch(@FN, KT0);
K = KT(1); T = KT(2);
disp(['K = ', num2str(K), ' T = ', num2str(T)])
disp(['C = ', num2str(C)])
function C = FN(KT)
K = KT(1); T = KT(2);
cc=15000;
cp=10000;
crg=200000;
rho=0.5;
eta=56.9;
beta=2.6;
alpha=1.63;
delta=0.015;
fn1 = @(K,T) ((K.*T-rho*(K-1).*T)/eta).^beta;
fn2 = @(K,T) (((K-1).*T-rho*(K-1).*T)/eta).^beta;
fn3 = @(K,T) ((K-1).^(beta-1).*T.^beta)/eta^beta;
H = @(K,T) alpha*(fn1(K,T) - fn2(K,T)) - delta*beta*fn3(K,T);
SM = 0;
for m = 1:K
SM = SM + H(m,T);
end
C = ((K-1)*cp + crg + cc*SM)./(K.*T);
end
Unfortunately, I think the function has many local minima, so there's no certainty that the above is a global minimum!
2 件のコメント
Alan Stevens
2022 年 9 月 5 日
Like this?
KT0 = [1, 10]; % initial guesses
[KT, C] = fminsearch(@FN, KT0);
K = KT(1); T = KT(2);
disp(['K = ', num2str(K), ' T = ', num2str(T)])
disp(['C = ', num2str(C)])
% Plot 3d graph
k = 1:20; t = 1:10:200;
nk = numel(k); nt = numel(t);
c = zeros(nk,nt);
for i = 1:nk
for j = 1:nt
c(i,j) = FN([k(i), t(j)]);
end
end
[x,y] = meshgrid(t,k);
surf(x,y,log10(c)),grid
xlabel('T'), ylabel('K'), zlabel('log10(C)')
function C = FN(KT)
K = KT(1); T = KT(2);
cc=15000;
cp=10000;
crg=200000;
rho=0.5;
eta=56.9;
beta=2.6;
alpha=1.63;
delta=0.015;
fn1 = @(K,T) ((K.*T-rho*(K-1).*T)/eta).^beta;
fn2 = @(K,T) (((K-1).*T-rho*(K-1).*T)/eta).^beta;
fn3 = @(K,T) ((K-1).^(beta-1).*T.^beta)/eta^beta;
H = @(K,T) alpha*(fn1(K,T) - fn2(K,T)) - delta*beta*fn3(K,T);
SM = 0;
for m = 1:K
SM = SM + H(m,T);
end
C = ((K-1)*cp + crg + cc*SM)./(K.*T);
end
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!