I have an optimization problem where my integration bounds depend on the maximizer and take the form max[1,Q+pa/2], where Q is the variable that I am maximizing with respect to.
For instance, my function U (utility), which I am maximizing is defined as follows:
I get a piecewise FOC for U, with respect to Q, and I'm able to solve for the optimal Q, given the parameters s, p, and pa, using fsolve. For example:
Here's my question:
I want to take the piecewise expression for the optimal Q and use it in a second maximization problem, where I am maximizing the following expression, a function of Q, with respect to (s,p) (and pa, m, and K are all given parameters):
profit:=simplify(p*Q_opt + s*subs(Q=Q_opt),y) + m*(K-subs(Q=Q_opt,y)));
and Q_opt would be my expression for the optimal Q
returns an error:
Error, (in fsolve) Can't handle expressions with typed procedures
because I have defined Q_opt as a piecewise function that depends on Q_opt itself (since the integration bound that I need to check is Q+pa/2<=1), i.e.
I have also tried using the following procedure, where I define Q_Case_1 and Q_Case_2 as the expressions for the optimal Q depending on whether Q+pa/2<=1 (Case 1) or Q+pa/2>1 (Case 2):
> if Q<1-1/2*pa then
> p*Q_Case_1 + s*subs(Q=Q_Case_1,y) + m*(K-subs(Q=Q_Case_1,y));
> p*Q_Case_2 + s*subs(Q=Q_Case_2,y) + m*(K-subs(Q=Q_Case_2,y));
> end if;
> end proc:
and get an error:
Error, (in profit) cannot determine if this expression is true or false: Q < .6000000000
This doesn't work since Q is not known when Maple goes to evaluate the if statement in proc!
Clearly my problem is the recursive nature of my definition of the optimal Q. What is the correct implementation for this optimization problem? Thanks!