facing problem in optimization using GA

조회 수: 2(최근 30일)
MD NASAR
MD NASAR 2012년 7월 1일
Hi all
i want the value of p(t),q(t) and a(t) and the value of t from 1 to 25 with minimizing a function z, code is given below,
function z=opt19(p,q,a)
M=100;
r=0.8;
alpha=0.45;
beta=0.75;
gama=0.1;
d=0.004;
h=0.4;
n=100;
nn=15;
x = zeros(nn,1);
a = zeros(nn,1);
p = zeros(nn,1);
c = zeros(nn,1);
q = zeros(nn,1);
lembda = zeros(nn,1);
delT=1;
x(1)=2;
c(1)=1580;
lembda(1)=150;
for t=1:nn-1
p(t)=c(t)+lembda(t)+1/d;
q(t)=exp(1/x(t)-1)*log10(c(t)/n);
c(t)=n*q(t)^x(t)-1;
a(t)=(p(t)-c(t)+lembda(t)*beta*(M-x(t))*exp(-d*p(t))*exp(h*q(t)));
z=((p(t)-1200+150)*(-0.004)*(0.45+0.75*log10(abs(a(t)))+0.1*2)*(100-2)*exp(-(.004)*p(t))*exp(.4*q(t))...
+(0.45+0.75*log10(abs(a(t)))+0.1*2)*(100-2)*exp(-(.004)*p(t))*exp(.4*q(t)))^(2)...
+((p(t)-1200+150)*0.4*(0.45+0.75*log10(abs(a(t)))+0.1*2)*(100-2)*exp(-(.004)*p(t))*exp(.4*q(t))...
+100*(2-1)*q(t)^(2-2)*(0.45+0.75*log10(abs(a(t)))+0.1*2)*(100-2)*exp(-(.004)*p(t))*exp(.4*q(t)))^(2)+...
((p(t)-1200+150)*0.75/a(t)*(100-2*exp(-(.004)*p(t))*exp(.4*q(t))-1))^(2);
x(t+delT)=x(t)+delT*(alpha+beta*log10(abs(a(t)))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t));
gx=exp(-d*p(t))*exp(h*q(t))*(gama*M-alpha-beta*log10(a(t))-2*gama*x(t));
cx=n*q(t)^(x(t)-1)*log10(q(t));
g=(alpha+beta*log10(a(t))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t));
lembda(t+delT)=lembda(t)+delT*(r*lembda(t)-gx*(p(t)-c(t)+lembda(t))+cx*g);
end
my problem is how to write objective function, i wrote the code please tell me how i will solve my problem please.
Thank you.

답변(1개)

Alan Weiss
Alan Weiss 2012년 7월 2일
Your code accepts arguments p, q, and a, and then overwrites them with different values (zeros(nn,1)). So I am not sure what your optimization variables are.
In any case, fmincon wants a single variable. I don't know what your variables are, but suppose they are the p, q, and a variables. Then you would write an objective function file such as
function f = objfun(x)
p = x(1:13);
q = x(14:26);
a = x(27:end);
(...calculations using p, q, and a go here)
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
MD NASAR
MD NASAR 2012년 7월 6일
Sir thanx for reply, Actually i want to predict the market for p(t) ie price at time t,q(t), quality at time t and q belongs from 0 to 1 and a(t) advetisment cost at time t. i want to solve it using genetic algorithm, algoritm is given below. based on this algorithm i want the solution sir please help me i am not able to do this.
Step 1. t=0,n=1,x(0)=x and lembd(0)=lembda.
Step 2. Solve p(t); q(t);A(t) and pnr by the genetic algorithm, where pt is the approximate solution for the price at the tth time, qt the approximate solution for the quality level at the tth time, And the approximate solution for the advertising expenditure at the tth time and Pnr the approximate solution for the profit at the tth time.
Step 3. Check the solution set with the second-order optimality onditions. If it satisfies the conditions ie z, then print pn; qn;An and pnr and go to
step 4. Otherwise, go to step 9. Step 4. t =t+delT and compute x(t) and lembda(t)
Step 5. If lembda(t)= 0, then go to step 7; otherwise, go to step 6.
Step 6. n = n + 1, and go to step 2.
Step 7. Calculate and print total profit.
Step 8. Stop.
Step 9. Print `no solution’ and stop.
sir please tell me all equation is in my first post.
thank you. Mohammad Nasar.

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by