MathGroup Archive 2007

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

Search the Archive

Re: Is this a problem in mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74642] Re: Is this a problem in mathematica?
  • From: "dimitris" <dimmechan at yahoo.com>
  • Date: Thu, 29 Mar 2007 02:34:40 -0500 (EST)
  • References: <eud3g1$l0t$1@smc.vnet.net><eudcsd$s4m$1@smc.vnet.net>

>Maximize and NMaximize find the global minimum.

=C9 mean global maximim.

It's the hot weather here in Greece that cause
now and then mistakes like this in my posts!

I apologize!

Best Regards
Dimitris

=CF/=C7 dimitris =DD=E3=F1=E1=F8=E5:
> No problem.
>
> I copy from the Help Browser...
>
> "Even if the same minimum is achieved at several points, only one is
> returned."
>
> "An important feature of Minimize and Maximize is that they always
> find global minima and maxima. Often functions will have various local
> minima and maxima at which derivatives vanish. But Minimize and
> Maximize use global methods to find absolute minima or maxima, not
> just local extrema. "
>
> Let see an example
>
> f[x_] := x + 2*Sin[x]
>
> The function has many local maxima and minima.
>
> Plot[f[x], {x, -10, 10}];
>
> Minimize and NMInimize find the global minimum.
>
> Minimize[{x + 2*Sin[x], -10 <= x <= 10}, x]
> N[%]
> NMinimize[{x + 2*Sin[x], -10 <= x <= 10}, x]
>
> {-Sqrt[3] - (8*Pi)/3, {x -> -((8*Pi)/3)}}
> {-10.109631217141658, {x -> -8.377580409572781}}
> {-10.10963121714166, {x -> -8.377580411890266}}
>
> Maximize and NMaximize find the global minimum.
>
> Maximize[{x + 2*Sin[x], -10 <= x <= 10}, x]
> N[%]
> NMaximize[{x + 2*Sin[x], -10 <= x <= 10}, x]
>
> {Sqrt[3] + (8*Pi)/3, {x -> (8*Pi)/3}}
> {10.109631217141658, {x -> 8.377580409572781}}
> {10.10963121714166, {x -> 8.377580409158735}}
>
> If you want to find all the local extremums, then you can work as
> follows:
>
> Reduce[Derivative[1][f][x] == 0 && -10 <= x <= 10, x]
> {ToRules[%]}
> f[x] /. %
> N[%]
>
> x == -((8*Pi)/3) || x == -((4*Pi)/3) || x == -((2*Pi)/3) || x=
 =
> ==
> (2*Pi)/3 || x == (4*Pi)/3 || x == (8*Pi)/3
> {{x -> -((8*Pi)/3)}, {x -> -((4*Pi)/3)}, {x -> -((2*Pi)/3)}, {x ->
> (2*Pi)/3}, {x -> (4*Pi)/3}, {x -> (8*Pi)/3}}
> {-Sqrt[3] - (8*Pi)/3, Sqrt[3] - (4*Pi)/3, -Sqrt[3] - (2*Pi)/3, Sqrt[3]
> + (2*Pi)/3, -Sqrt[3] + (4*Pi)/3, Sqrt[3] + (8*Pi)/3}
> {-10.109631217141658, -2.4567393972175133, -3.8264459099620725,
> 3=2E8264459099620725, 2.4567393972175133, 10.109631217141658}
>
> Or
>
> << "NumericalMath`IntervalRoots`"
>
> IntervalBisection[Derivative[1][f][x], x, Interval[{-10., 10}], 0.001,
> MaxRecursion -> 16]
> List @@ %
> (FindRoot[Derivative[1][f][x] == 0, {x, #1[[1]], #1[[2]]}] & ) /@ %
> f[x] /. %
>
> Interval[{-8.377685546875014, -8.377075195312507},
> {-4.188842773437508, -4.188232421875004},
>   {-2.0947265625000053, -2.0941162109375036}, {2.0941162109375,
> 2=2E0947265625000018}, {4.188232421875, 4.1888427734375036},
>   {8.3770751953125, 8.377685546875007}]
> {{-8.377685546875014, -8.377075195312507}, {-4.188842773437508,
> -4.188232421875004},
>   {-2.0947265625000053, -2.0941162109375036}, {2.0941162109375,
> 2=2E0947265625000018}, {4.188232421875, 4.1888427734375036},
>   {8.3770751953125, 8.377685546875007}}
> {{x -> -8.377580409572781}, {x -> -4.1887902047863905}, {x ->
> -2.0943951023931957}, {x -> 2.0943951023931957},
>   {x -> 4.1887902047863905}, {x -> 8.377580409572781}}
> {-10.10963121714166, -2.4567393972175138, -3.8264459099620725,
> 3=2E8264459099620725, 2.4567393972175138, 10.10963121714166}
>
> The following code finds additionally which local extremum is minimum
> and which is maximum.
>
> Reduce[Derivative[1][f][x] == 0 && -10 <= x <= 10, x]
> ext = x /. {ToRules[%]}
> ({#1, f[#1]} & ) /@ ext
> ({#1, Derivative[1][f][#1]} & ) /@ ext
> ({#1, Derivative[2][f][#1]} & ) /@ ext
> maxm = Cases[%, {(x_)?NumericQ, (y_)?NumericQ} /; y < 0]
> minm = Cases[%%, {(x_)?NumericQ, (y_)?NumericQ} /; y > 0]
>
> x == -((8*Pi)/3) || x == -((4*Pi)/3) || x == -((2*Pi)/3) || x=
 =
> ==
> (2*Pi)/3 || x == (4*Pi)/3 || x == (8*Pi)/3
> {-((8*Pi)/3), -((4*Pi)/3), -((2*Pi)/3), (2*Pi)/3, (4*Pi)/3, (8*Pi)/3}
> {{-((8*Pi)/3), -Sqrt[3] - (8*Pi)/3}, {-((4*Pi)/3), Sqrt[3] - (4*Pi)/
> 3}, {-((2*Pi)/3), -Sqrt[3] - (2*Pi)/3},
>   {(2*Pi)/3, Sqrt[3] + (2*Pi)/3}, {(4*Pi)/3, -Sqrt[3] + (4*Pi)/3},
> {(8*Pi)/3, Sqrt[3] + (8*Pi)/3}}
> {{-((8*Pi)/3), 0}, {-((4*Pi)/3), 0}, {-((2*Pi)/3), 0}, {(2*Pi)/3, 0},
> {(4*Pi)/3, 0}, {(8*Pi)/3, 0}}
> {{-((8*Pi)/3), Sqrt[3]}, {-((4*Pi)/3), -Sqrt[3]}, {-((2*Pi)/3),
> Sqrt[3]}, {(2*Pi)/3, -Sqrt[3]}, {(4*Pi)/3, Sqrt[3]},
>   {(8*Pi)/3, -Sqrt[3]}}
> {{-((4*Pi)/3), -Sqrt[3]}, {(2*Pi)/3, -Sqrt[3]}, {(8*Pi)/3, -Sqrt[3]}}
> {{-((8*Pi)/3), Sqrt[3]}, {-((2*Pi)/3), Sqrt[3]}, {(4*Pi)/3, Sqrt[3]}}
>
>
> Dimitris
>
> =CF/=C7 traz =DD=E3=F1=E1=F8=E5:
> > Let's say I wanna solve this problem:
> >
> > Determine point(s) on y = x^2 +1 that are
> > closest to (0,2).
> >
> > So in mathematica:
> >
> > minDist = (x - 0)^2 + (y - 2)^2;
> > Minimize[minDist, y == 1 + x^2, {x, y}]
> >
> > Output will give you: x -> -1/Sqrt[2], y -> 3/2
> >
> > but x also has another answer: +1/Sqrt[2]. Is this a problem in mathema=
ti=
> ca or can my code be changed to output the other value of x for the minim=
um=
>  distance?



  • Prev by Date: Re: Definite Integration in Mathematica
  • Next by Date: Re: Closing All Input Cells at Once
  • Previous by thread: Re: Is this a problem in mathematica?
  • Next by thread: Pattern evaluation depending on order of definitions