-1
$\begingroup$

can I plot Cobb-Douglas function in 2D without using ContourPlot?

I have this function:

u[x1_, x2_] := Log[x1] + 2*Log[x2];

and now I plot it using:

ContourPlot[u[x1,x2], {x1, 0, 10}, {x2, 0, 10}]

how can i 2d-plot it using simple Plot?

$\endgroup$
  • $\begingroup$ ...Plot[] is intended for functions of one variable. You have two variables in your function, so you'll have to set one of those two to a constant. $\endgroup$ – J. M. will be back soon May 6 '16 at 12:49
  • $\begingroup$ I wrote a function to get a numerical solution for an implicit curve here, which can be useful in cases where the equations cannot be solved symbolically. Here they can be, but I'm curious why not use ContourPlot? It can be combined with other graphics, and it does a pretty good job on this function. I don't see the point, unless it's a homework exercise. $\endgroup$ – Michael E2 May 6 '16 at 13:49
2
$\begingroup$
u[x1_, x2_] = Log[x1] + 2*Log[x2];

cp = ContourPlot[u[x1, x2], {x1, 0, 10}, {x2, 0, 10}, PlotPoints -> 100]

enter image description here

Solve for x2 along the contours

f[x1_, c_] = x2 /. Solve[c == u[x1, x2], x2, Reals][[1]]

(*  E^(c/2)/Sqrt[x1]  *)

Plot the contours

plt = Plot[
  Evaluate[
   Table[
    Tooltip[f[x1, c], c],
    {c, -2, 6, 2}]],
  {x1, 0, 10},
  PlotRange -> {0, 10},
  Frame -> True,
  AspectRatio -> 1,
  PlotStyle -> Thick,
  ImageSize -> 360]

enter image description here

Overlaying the plots

Show[cp, plt]

enter image description here

EDIT: For a specific {x1, x2} then the contour is just u[x1, x2]

Manipulate[
 Module[{c = u[x1, x2]},
  Plot[Tooltip[f[x, c], c], {x, 0, 10},
   PlotRange -> {0, 10},
   Frame -> True,
   FrameLabel -> (Style[TraditionalForm[#], Bold, 14] & /@
      {Subscript[x,
         1], Subscript[x, 2]}),
   AspectRatio -> 1,
   Epilog -> {Red, AbsolutePointSize[4], Point[{x1, x2}]}]],
 {{x1, 5., Subscript[x, 1]}, 0, 10, Appearance -> "Labeled"},
 {{x2, 5., Subscript[x, 2]}, 0, 10,
  Appearance -> "Labeled"}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you,but I have another doubt: how can I draw only one curve that pass through fixed x1 and x2 ? $\endgroup$ – Motosega May 6 '16 at 19:34
  • $\begingroup$ @Motosega - see edit. Pick a point, any point ... $\endgroup$ – Bob Hanlon May 6 '16 at 20:18
  • $\begingroup$ it doesn't work. This code don't draw the blue curve... $\endgroup$ – Motosega May 6 '16 at 20:33
  • $\begingroup$ @Motosega - Works fine here. Try starting with a fresh kernel, perhaps you have some old definitions laying around. $\endgroup$ – Bob Hanlon May 6 '16 at 20:39

Your Answer

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

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