Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg71015] RE: [mg71004] Tricky visualization of maximization problem
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 4 Nov 2006 23:07:11 -0500 (EST)

Uwe,

Here is a third visualization of your maximization problem. In this
visualization we plot a vertical surface on the constraint line. It is easy
to see where the maximum values are. IteratorSubstitution is a DrawGraphics
routine that allows us to draw a surface where one of the plot iterators is
not between fixed values. In this case we want to draw a surface that goes
from zero to the value of f[x, y]. IteratorSubstitution produces a
parametrization with fixed iterators (as Mathematica demands). I will first
produce the graphic by parametrizing the circle. Afterwards I will produce
the graphic where we obtain points of the constraint equation from an
ImplicitPlot curve.

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}];

IteratorSubstitution[{Cos[t], Sin[t], z}, {z, 0, f[Cos[t], Sin[t]]}]
{{Cos[t], Sin[t], -w (Cos[2 t] - 2 (1 + Sin[2 t]))}, {w, 0, 1}}

Module[
    {size = 1.1},
    Draw3DItems[
      {SurfaceColor[LightCoral], EdgeForm[ColorMix[LightCoral, Black][0.5]],
        ParametricDraw3D[{Cos[t],
            Sin[t], -w (Cos[2 t] - 2 (1 + Sin[2 t]))}, {t, 0, 2Pi}, {w, 0,
1},
           PlotPoints -> {50, 15}]},
      NeutralLighting[0.2, 0.4, 0.1, 30°],
      Axes -> True,
      AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}},
      AxesLabel -> {x, y, None},
      BoxRatios -> {1, 1, 1},
      PlotLabel ->
        SequenceForm["\tMaximizing ", f[x, y], ", on ", c[x, y],
          "\n\t\t\tMaximum value: ", maxvalue],
      TextStyle -> {FontSize -> 12, FontWeight -> "Bold"},
      Background -> ColorMix[SeaGreen, White][0.85],
      ImageSize -> 500]
    ];

Suppose that we didn't know how to easily parametrize the constraint
equation. One approach is to get the line from ImplicitPlot and then fit
InterpolatingFunctions to the x and y coordinates. We can then use these in
IteratorSubstitution.

size = 1.1;
constraintpoints =
    First@Cases[
        ImplicitDraw[c[x, y], {x, -size, size}, {y, -size, size},
          PlotPoints -> 100], Line[pts_] -> pts, \[Infinity]];

xfun = ListInterpolation[First[Transpose[constraintpoints]]];
yfun = ListInterpolation[Last[Transpose[constraintpoints]]];

{tparam, iter} =
  IteratorSubstitution[{xfun[t], yfun[t], z}, {z, 0, f[xfun[t], yfun[t]]}]
(the output is only given in schematic form.)
{{InterpolatingFunction[...][t], InterpolatingFunction[...][t],
   w*(3*InterpolatingFunction[...][t]^2 + 4*InterpolatingFunction[...][t]*
      InterpolatingFunction[...][t] + InterpolatingFunction[...][t]^2)}, {w,
0, 1}}

Module[
    {size = 1.1},
    Draw3DItems[
      {SurfaceColor[LightCoral], EdgeForm[ColorMix[LightCoral, Black][0.5]],
        ParametricDraw3D[tparam, {t, 1, 361}, {w, 0, 1},
          PlotPoints -> {50, 15}]},
      NeutralLighting[0.2, 0.4, 0.1, 30°],
      Axes -> True,
      AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}},
      AxesLabel -> {x, y, None},
      BoxRatios -> {1, 1, 1},
      PlotLabel ->
        SequenceForm["\tMaximizing ", f[x, y], ", on ", c[x, y],
          "\n\t\t\tMaximum value: ", maxvalue],
      TextStyle -> {FontSize -> 12, FontWeight -> "Bold"},
      Background -> ColorMix[SeaGreen, White][0.85],
      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: Assuming non-integer values in Mathematica simplifications
  • Next by Date: Re: Matrix Output
  • Previous by thread: Re: Tricky visualization of maximization problem
  • Next by thread: RE: Tricky visualization of maximization problem