|
"Ozge Taskan" <lordgy@yahoo.com> wrote in message <hsr76f$pi6$1@fred.mathworks.com>...
> Thank you Roger ,
> Let me say it more clearly,the situation of item i is sent with driver j is shown with binary variable y(i,j) (1 if it is sent via driver j, 0 otherwise), therefore p(i,j) is the penalty cost of sending item i with driver j if item becomes late. My function is sum over i, j ==> p(i,j)*y(i,j)*(sum over x[(x-S(i))*P(X=x))] and P(X=x) is (lambda(i,j)*y(i,j))^x * exp(-lambda(i,j)*y(i,j)) / x-factorial and x starts from s(i) and goes to infinity or as you say may be to 1000. This part (x-S(i))*P(X=x)) is supposed to find an expected number. It is just one part of my objective function, in general I try to optimize my s(i) and y(i,j). So I try to assign drivers to items and find s(i) s for each item i. And I could not write this function to fminunc as a part of objective function.
> thank you very much in advance.
>
> Ozge
I am not certain this will help, but you can replace that infinite sum with a finite expression. I refer to what you call:
(x-S(i))*P(X=x)) ,
summed from x = S(i) to x = infinity. If you have the statistics toolbox, there is a function in it called 'poisscdf' which is the cumulative poisson distribution. The above sum can be expressed in terms of this function as follows:
(lambda-s)*(1-poisscdf(s-2,lambda)) + ...
s*lambda^(s-1)*exp(-lambda)/factorial(s-1) .
However this formula should be used with some care. If s is so large that poisscdf(s-2,lambda) is very close to 1, then when it is subtracted from 1 in the expression it loses relative accuracy, and it would have been better to do the sum directly since only a few more terms would have sufficed to approach infinity appropriately in such cases.
As far as the outer sum with respect to i and j is concerned, all the above quantities in the finite expression above are capable of receiving vector inputs, so the outer sum could also be done without any for-loops.
By the way, I don't know why you included the binary y(i,j) in the above poisson expressions along with lambda(i,j), since that whole inner sum is multiplied by y(i,j).
Roger Stafford
|