Maple derivative with sum() and product()

174 Views Asked by At

I am new to maple and have run into an issue optimizing wrt a term within sum() and or product(). Suppose I want to optimize a profit function function given by

\begin{align} Q : = p \cdot A \prod_{l=1}^{L-1} z_l^{a_l} - \sum_{l=1}^{L-1}w_lz_l \end{align}

wrt to input $z_l$. diff(Q,z[l]) yields nonsense and diff(Q,z[1]) zero. I am having trouble finding alternative methods generating the FOC. Any help is appreciated.

1

There are 1 best solutions below

0
On

As @Sil already has mentioned in a comment below your question, your problem is that you have a undetermined sum and product. For example assume you want to take derivative with respect to z2, how can Maple check if there is a z2 in your expression? L is not defined so it's not clear what indices exist in your expression. What you can do is as following. If you need the Q expression for different values of L, then define a function of L or a procedure with L as its input. So when you want to compute something related to Q of a specific L, you just put Q equal to the output of that procedure for your choice of L, then do the computations.

Qproc := proc(L) 
local l; 
return(p*A*product(z[l]^a[l],l=1..L-1)-add(w[l]*z[l],l=1..L-1); 
end proc:

This procedure returns you your Q expression for a given choice of L. Let's say I want $L=3$. Then I do as following.

Q:=Qproc(3);

The Maple output will be;

enter image description here

Then you can ask derivatives with respect to z1 and z2, because now they are in your expression (not like when you had an undetermined sum and product!).

for l to 3 - 1 do
print(expand(z[l]*diff(Q,z[l])));
end do;

The Maple output is;

enter image description here