1
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ Solve[FullSimplify[TC[K, L, q]] == 2 (640 + (5 + 4 2^(1/5)) q), {K, L}] $\endgroup$ Commented Dec 27, 2013 at 16:50
  • $\begingroup$ @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] ]? $\endgroup$ Commented Dec 27, 2013 at 17:28
  • $\begingroup$ Is this what you're after? mathematica.stackexchange.com/a/18706/193 $\endgroup$ Commented Dec 27, 2013 at 17:31
  • $\begingroup$ @belisarius Indeed! :) The only thing: Can I make it automatically choose the real-valued solution instead of, say, the first one? $\endgroup$ Commented Dec 27, 2013 at 17:37
  • $\begingroup$ @belisarius I've found this but I can't get any of the methods to work. Can you help? :) $\endgroup$ Commented Dec 27, 2013 at 18:42

1 Answer 1

3
$\begingroup$

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)]
$\endgroup$
5
  • $\begingroup$ On the top of the page you find a "help" link. There you can choose different help topics. One of them is how to format a post properly. $\endgroup$
    – halirutan
    Commented Dec 28, 2013 at 0:28
  • $\begingroup$ @halirutan - cheers, and thanks for editing! $\endgroup$
    – ciao
    Commented Dec 28, 2013 at 0:32
  • $\begingroup$ I made a huge omission in my first update to the question. See the updated question. $\endgroup$ Commented Dec 28, 2013 at 3:07
  • $\begingroup$ @Svend - ah- I thought the question a bit simple. I've added to my original answer. Again, assuming you put the solve set into 'res', this should return the set where k and l are reals. $\endgroup$
    – ciao
    Commented Dec 28, 2013 at 6:26
  • $\begingroup$ Great. Thank you. $\endgroup$ Commented Dec 28, 2013 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.