I'm trying to illustrate an optimization problem with a piecewise constraint creating a kink at the maximum value of T if n>0.

ClearAll[U, f, c, α, T, w, l, n, sols, c1transf, c2transf, fstar, cstar]
U[f_, c_, α_] := f^α*c^(1 - α);
Bconstrtransf[f_, c_, T_, w_, n_]:= Piecewise[{{c - (T - f)*w - n, f < T}}];
MRS = D[U[f, c, α], f]/D[U[f, c, α], c]
AbsSlpCon = D[Bconstrtransf[f, c, T, w, n], f];
TC = MRS - AbsSlpCon;
f < T

sols = Solve[{TC == 0, Bconstrtransf[f, c, T, w, n] == 0}, {f, c}]
{fstar, cstar} = {f, c} /. Last[sols]

sols2 = Solve[{TC == 0, Bconstrtransf[f, c, T, w, n] == 0}, {f, c}]
fcopttransf[T_, w_, α_, n_] := Evaluate[{f, c} /. Last[sols2]]

c1transf[T_, w_, n_] :=  c /. Solve[Bconstrtransf[f, c, T, w, n] == 0, c][[1]]
c2transf[T_, w_, α_, n_] =  Quiet[c /. Solve[U[## & @@ fcopttransf[T, w, α, n],α] == U[f, c, α], c][[1]]];

Manipulate[Plot[{c1transf[T, w, n], c2transf[T, w, α, n]}, {f, 0, 24}, PlotRange -> {25, 6000}, Epilog -> {Red, PointSize@Large, Point@fcopttransf[T, w, α, n]}], {T, 8, 24}, {w, 100, 
  200}, {{α, 1/2}, 10^-2, 1}, {n, 500, 2000}]

My problems are that

  1. I can't get an output for c2transf or the optimal point

  2. I would like to have a vertical line from (T,n) to (T,0) to show that c1transf creates a "visual set."

Update: I know that the optimal solution is either f*<T or f*=T and the problem is a variation of this: Manipulate and Plot of Tangent Point in Optimization Problem: Solve Problems

Any hints or solutions for this problem?


  • $\begingroup$ You will have noticed the warning from Solve ("Equations may not give solutions for all "solve" variables."). You'll want to start fixing that. Can you impose any restrictions on the parameter space? Remember that MMA works with complex numbers by default, so if you want Reals, you want to specify that, etc. $\endgroup$ – MarcoB Nov 16 at 23:48
  • $\begingroup$ The problem is similar to this one: mathematica.stackexchange.com/questions/234726/… The difference is that adding the variable "n" creates a different constraint: Bconstrtransf[f_, c_, T_, w_, n_]:= Piecewise[{{c - (T - f)*w - n, f < T}}]; vs. Bcon[f_, c_, T_, w_] := c - (T - f)*w The only constraint is that f=<T and the optimal solution for (f*,c*) is either f*<T or f*=T. $\endgroup$ – Tom G Nov 17 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.