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 view (last 30 days)
Show older comments
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 Comments
Torsten
on 28 Aug 2022
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) ?
Answers (1)
Alan Stevens
on 30 Aug 2022
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 Comments
Alan Stevens
on 5 Sep 2022
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
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!