1

Consider the following code:

ClearAll[K, L, λ, q, r, w]

TC[K_, L_, q] := w*L + r*K + 10*q
Phi[K_, L_, λ_] := TC[K, L, q] - λ*(10*K^(4/5)*(L - 40)^(1/5) - q)
Phi[K, L, λ]

FullSimplify[{
  D[Phi[K, L, λ], K],
  D[Phi[K, L, λ], L],
  D[Phi[K, L, λ], λ]
  }]

FullSimplify[
 Solve[{
   D[Phi[K, L, λ], K] == 0,
   D[Phi[K, L, λ], L] == 0,
   D[Phi[K, L, λ], λ] == 0
   }, {K, L, λ}]
 ]

r = 64;
w = 32;
FullSimplify[TC[K, L, q]]

Is it possible to automatically assign the real-valued solutions for K and L to get the output

2 (640 + (5 + 4 2^(1/5)) q)

with executing the last command?

Update

After hints from Artes, I've managed to always get the function TC for real-valued K and L. However, how do I print only the real-values [which I forgot to mention the first time I updated the question] of K and L when I solve the system of equations? When executing

F[k_, l_] := 10*k^(4/5)*(l - 40)^(1/5)
TC[k_, l_, q_] := w*l + r*k + 10*q
Phi[k_, l_, λ_] := TC[k, l, q] - λ*(F[k, l] - q)
expressions = {D[Phi[k, l, λ], k], D[Phi[k, l, λ], l], D[Phi[k, l, λ, λ]};
FullSimplify[Solve[expressions == {0, 0, 0}, {k, l, λ}]]

I get five solutions;

{{k -> (q w^(1/5))/(5 2^(3/5) r^(1/5)), 
  l -> 40 + (q r^(4/5))/(20 2^(3/5) w^(4/5)), λ] -> (
   r^(4/5) w^(1/5))/(
   4 2^(3/5))}, {k -> -(((-1)^(1/5) q w^(1/5))/(5 2^(3/5) r^(1/5))), 
  l -> 40 - ((-1)^(1/5) q r^(4/5))/(20 2^(3/5) w^(4/5)), λ -> 
   r^(4/5) w^(1/5) Root[-1 + 8192 #1^5 &, 2]}, {k -> ((-1)^(2/5) q w^(
    1/5))/(5 2^(3/5) r^(1/5)), 
  l -> 1/40 (1600 + ((-2)^(2/5) q r^(4/5))/w^(
      4/5)), λ -> ((-1)^(2/5) r^(4/5) w^(1/5))/(
   4 2^(3/5))}, {k -> -(((-1)^(3/5) q w^(1/5))/(5 2^(3/5) r^(1/5))), 
  l -> 40 - ((-(1/2))^(3/5) q r^(4/5))/(
    20 w^(4/5)), λ -> -(((-1)^(3/5) r^(4/5) w^(1/5))/(
    4 2^(3/5)))}, {k -> ((-1)^(4/5) q w^(1/5))/(5 2^(3/5) r^(1/5)), 
  l -> 40 + ((-1)^(4/5) q r^(4/5))/(
    20 2^(3/5) w^(4/5)), λ -> ((-1)^(4/5) r^(4/5) w^(1/5))/(
   4 2^(3/5))}}

P.S. q, r, and w are all positive numbers.

Svend Tveskæg
  • 425
  • 5
  • 14
  • Solve[FullSimplify[TC[K, L, q]] == 2 (640 + (5 + 4 2^(1/5)) q), {K, L}] – Dr. belisarius Dec 27 '13 at 16:50
  • @belisarius I mean: If I execute FullSimplify[ Solve[{ D[Phi[K, L, λ], K] == 0, D[Phi[K, L, λ], L] == 0, D[Phi[K, L, λ], λ] == 0 }, {K, L, λ}] ], I get the solution K -> (q w^(1/5))/(5 2^(3/5) r^(1/5)), L -> 40 + (q r^(4/5))/(20 2^(3/5) w^(4/5)). Can I automatically assign these values to K and L and therefore get 2 (640 + (5 + 4 2^(1/5)) q) if I execute r = 64; w = 32; FullSimplify[TC[K, L, q] ]? – Svend Tveskæg Dec 27 '13 at 17:28
  • Is this what you're after? http://mathematica.stackexchange.com/a/18706/193 – Dr. belisarius Dec 27 '13 at 17:31
  • @belisarius Indeed! :) The only thing: Can I make it automatically choose the real-valued solution instead of, say, the first one? – Svend Tveskæg Dec 27 '13 at 17:37
  • @belisarius I've found this but I can't get any of the methods to work. Can you help? :) – Svend Tveskæg Dec 27 '13 at 18:42
  • This post is what you are looking for How to find lattice points on a line segment?, especially II solution. If you need to specify the real domain use e.g. Solve[ eqs, vars, Reals]. – Artes Dec 27 '13 at 18:44
  • @Artes Can I make you give an answer, using this method? (1) I'm not sure how to use it and (2) I can accept your question and thereby finish my question. – Svend Tveskæg Dec 27 '13 at 18:48
  • @SvendTveskæg I'm not going to answer your question since: 1. I don't like defining functions depending on parameters which are not explicit variables (it isn't appropriate practice) e.g. TC depends on w and r. 2. You shouldn't use capital K. – Artes Dec 27 '13 at 18:56
  • @SvendTveskæg By the way you can do this: TC[k, l, q] /. Solve[{D[Phi[k, l, λ], k] == 0, D[Phi[k, l, λ], l] == 0, D[Phi[k, l, λ], λ] == 0}, {k, l, λ}, Reals] // Simplify – Artes Dec 27 '13 at 19:07
  • @Artes Hmmm. I'm reather tired and can't think properly right now, I can feel. Can I make you give a full answer (with your preferred changes)? – Svend Tveskæg Dec 27 '13 at 19:18

1 Answers1

3

Simply save the FullSimplify result (the one before the r = ... assignment), say as "res". Then use

FullSimplify[ TC[K,L,q]]/. res // FullSimplify//First

gives exactly the result you posted. Remove the first (and add a rule to filter only reals) to substitute all real solutions.

Per your update, this should return the $k$ and $l$ (along with any other solution components) where $k$ and $l$ are restricted to reals:

Pick[(res), Refine[ # ∈ Reals, Assumptions -> {q, w, r} ∈ Reals 
                    && 0 < q && 0 < w && 0 < r] & /@ ({k, l} /. res)]
Artes
  • 57,212
  • 12
  • 157
  • 245
ciao
  • 25,774
  • 2
  • 58
  • 139