# 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

4 views (last 30 days)
lamia on 28 Aug 2022
Commented: lamia on 20 Sep 2022
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))
lamia on 5 Sep 2022
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

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)])
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!
lamia on 20 Sep 2022
Thank you, that helped so much
please I did not understand how you declared the values of k I mean it is an integer
may i mail you ?