From: Steven Lord on 14 Jun 2010 10:03 "mohamad ali " <itani.mai(a)hotmail.com> wrote in message news:hv3s8b$lrs$1(a)fred.mathworks.com... > 1) k variable is not part of the constraint...it is only used to indicate > how many times i need to generate the constraint.For example if M=2 then i > have to write the first constraint 2 times and the also the second > constraint 2 times...so don't mind the k. If the k is not part of the constraint, then are you specifying exactly the same constraint multiple times? Don't. > 2) am interested in the way you joined my 2 parameters the C's and the > a's.I was wondering if you could elaborate more in code. You already "joined" the parameters -- all I did was point out that once you know a(1, 1) you can _compute_ a(1, 2) given the constraint that they sum up to 1, so you don't need to include them _both_ in the parameters-to-be-optimized. > 3) I will write now the objective function which for me i think is the > major problem. > Remark: flow,xx,u,Gamma,M are all fixed variables. > > function fval = ObjFunctrial(X,flow,xx,u,Gamma,M) > f=0; > for i=1:xx > for j=1:M > f=f + ((flow(i)*X(M+xx))/(u*X(i)-(flow(i)*X(M+xx)))); > end > end fval=f/Gamma; > end > X=[C1,C2,C3,C4,C5,C6,a(1,1),a(1,2),a(2,1),a(2,2),a(3,1),a(3,2),a(4,1),a(4,2),a(5,1),a(5,2),a(6,1),a(6,2)] > xx=6 in this case > Note: I need to get every variable and also f.For example, i want to get > the value of C1 which is X(1) and a(1,1) and a(1,2) in which a(1,1) is > C(1+xx) and a(2,2) is C(2+xx) and then C2 and a(2,1) a(2,2)..and so on > and on until i get all 18 variables and then use them to calculate f. > > Am getting the following error message: > ??? Error using ==> barrier at 14 > Objective function is undefined at initial point. Fmincon > cannot continue. This would suggest to me that the problem is NOT in your objective function but in your initial condition vector. But I would break apart the X vector _first_ into a vector of C's and a vector of a's: C = X(1:6); a1 = X(7:12); f = 0; for k = 1:6 num1 = flow(k)*a1(k); den1 = u*C(k)-num1; num2 = flow(k)*(1-a1(k)); den2 = u*C(k)-num2; f = f+(num1./den1)+(num2./den2); end But note that if one of your C's is 0 and its corresponding a1 is either 0 or 1, one of the terms will be of the form 0/0 which will result in NaN which I believe will result in the error you received. > 4) I have also one last problem am facing which is the lower bound.I have > to put for example C(1)>=[flow(1)*a(1,1)]/u; but for all variables > Translated to X: > X(i)>=[flow(i)*X(i+xx)]/u; > The problem is that X vector is both an output and input at the same > time..so how can i do that in coding. Rewrite your constraint so that all the instances of X appear on the same side. u*X(i) >= flow(i)*X(i+xx) u*X(i) -flow(i)*X(i+xx) >= 0 -u*X(i) +flow(i)*X(i+xx) <= 0 Now this looks like it can be converted into the form A*x <= b, doesn't it? I'll leave you to generate the appropriate row or rows of A. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: mohamad ali on 16 Jun 2010 13:57
I will write now the objective function which for me i think is the major problem. Remark: flow,xx,u,Gamma,M are all fixed variables. function fval = ObjFunctrial(X,flow,xx,u,Gamma,M) f=0; for i=1:xx for j=1:M f=f + ((flow(i)*X(M+xx))/(u*X(i)-(flow(i)*X(M+xx)))); end end fval=f/Gamma; end X=[C1,C2,C3,C4,C5,C6,a(1,1),a(1,2),a(2,1),a(2,2),a(3,1),a(3,2),a(4,1),a(4,2),a(5,1),a(5,2),a(6,1),a(6,2)] Am still getting the following error message: ??? Error using ==> barrier at 14 Objective function is undefined at initial point. Fmincon cannot continue. This would suggest to me that the problem is NOT in your objective function but in your initial condition vector. Q:What do you mean by the initial condition vector?...Is it the X vector or the xo in which i set it all to zero. But I would break apart the X vector _first_ into a vector of C's and a vector of a's: C = X(1:6); a1 = X(7:12); f = 0; for k = 1:6 num1 = flow(k)*a1(k); den1 = u*C(k)-num1; num2 = flow(k)*(1-a1(k)); den2 = u*C(k)-num2; f = f+(num1./den1)+(num2./den2); end But note that if one of your C's is 0 and its corresponding a1 is either 0 or 1, one of the terms will be of the form 0/0 which will result in NaN which I believe will result in the error you received. Q:How can I prevent that from happening?..that my C's should not be zero or my a's should not be zero also... Thanks for the help. Ali. |