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
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) ?
lamia
lamia 2022-9-5
K is a variable that I didn't know how to define in the script, so I opted for the approach above, in order to find the optimal k and T. but I think it's not the right one
T is the value of the optimal period and K is the number of optimal periods

请先登录,再进行评论。

回答(1 个)

Alan Stevens
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)])
K = 2 T = 108.5802
disp(['C = ', num2str(C)])
C = 1571.1955
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 个评论
lamia
lamia 2022-9-5
thank you, something like this yes
but how to plot the graphs , when I add the curve drawing instructions it doesn't work
Alan Stevens
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)])
K = 2 T = 108.5802
disp(['C = ', num2str(C)])
C = 1571.1955
% 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 CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by