MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Tricky visualization of maximization problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71014] RE: [mg71004] Tricky visualization of maximization problem
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 4 Nov 2006 23:07:10 -0500 (EST)

Uwe,

Here is a second visualization, this time a contour plot with the constraint
line plotted on top of it. A 'cartographic' coloring function is used where
'sea level' is placed at the value that maximizes the function on the
constraint and mindomain and maxdomain are the minimimum and maximum values
of f on the plot domain.

Needs["DrawGraphics`DrawingMaster`"]

f[x1_, x2_] := x1^2 + 4*x1*x2 + 3*x2^2
c[x1_, x2_] := x1^2 + x2^2 == 1

{maxvalue, xysols} = Maximize[{f[x, y], c[x, y]}, {x, y}];

mindomain =
    First@Minimize[{f[x, y], -1.1 < x < 1.1 && -1.1 < y < 1.1}, {x, y}];
maxdomain =
    First@Maximize[{f[x, y], -1.1 < x < 1.1 && -1.1 < y < 1.1}, {x, y}];

colorfun =
    TwoColorScale[{mindomain, maxvalue,
        maxdomain}, {ColorMix[Peacock, Black][0.5], Peacock,
        ColorMix[Peacock, White][0.8], ColorMix[Melon, White][0.8], Melon,
        ColorMix[Melon, Black][0.5]}];

Module[
    {size = 1.1, xmax, ymax},
    {xmax, ymax} = {x, y} /. xysols // N;
Draw2D[
      {ContourDraw[f[x, y], {x, -size, size}, {y, -size, size},
          ColorFunction -> colorfun, ColorFunctionScaling -> False,
          Contours -> {0.001, 1, 2, 3, maxvalue, 5, 6, 7, 8, 9},
          PlotPoints -> 100],
        ImplicitDraw[c[x, y], {x, -size, size}, {y, -size, size},
          PlotPoints -> 100],
        CirclePoint[#, 4, Black, Red] & /@ {{xmax, ymax}, -{xmax, ymax}}},
      AspectRatio -> Automatic,
      PlotLabel ->
        SequenceForm["\tMaximizing ", f[x, y], ", on ", c[x, y],
          "\n\t\t\tMaximum value: ", maxvalue],
      TextStyle -> {FontSize -> 12, FontWeight -> "Bold"},
      Frame -> True,
      ImageSize -> 500]
    ];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Uwe Ziegenhagen [mailto:newsgroup at ziegenhagen.info]
To: mathgroup at smc.vnet.net

Hi,

I want to maximize

x1^2 + 4*x1*x2 + 3*x2^2  (eq.1)

under the constraint

x1^2 + x2^2 == 1 (eq. 2)

So far no problem, Maximize gives me 2 + sqrt(5)

But how can I display this visually?

For eq. 1 I can use Plot3D[], for eq. 2 ImplicitPlot[] but how to have
them in one picture?


Thanks in advance,


Uwe



  • Prev by Date: Re: Tricky visualization of maximization problem
  • Next by Date: Re: Tricky visualization of maximization problem
  • Previous by thread: Re: Tricky visualization of maximization problem
  • Next by thread: Re: Tricky visualization of maximization problem