MathGroup Archive 2011

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

Search the Archive

Re: Problem with "Which"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122232] Re: Problem with "Which"
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Fri, 21 Oct 2011 07:28:03 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j7p1t7$5ks$1@smc.vnet.net>

On Thu, 20 Oct 2011 12:49:59 +0100, mbmb <sb at 9y.com> wrote:

> Who can check my module?
>
> KD[f0_, a0_, b0_] := Module[{f = f0, a = a0, b = b0},
> f2 = D[f, {x, 2}];
> ew = Solve[D[f, x] == 0, x, Reals];
> Print["Extremwerte: ", {Which[f2 > 0, "T", f2 < 0, "H", f2 = 0, "S" ],  
> x, f} /. ew];
> Print["Extremwerte: ", {If[f2 > 0, "T", "H" ], x, f} /. ew];
> ]
>
> When I enter: KD[x^3 - 3 x^2, -1, 4] the output is
>
> Extremwerte: {{Which[-6+6 x<0,H,f2=0,S],0,0},{T,2,-4}}
>
> whereas the IF-line gives
>
> Extremwerte: {{H,0,0},{T,2,-4}}
>
> Why can't I use Which in this case. Why doesn't Mathematica evaluate f2  
> in all cases?
>

Try:

KD[f0_, a0_, b0_] := Module[{f = f0, a = a0, b = b0},
f2 = D[f, {x, 2}];
ew = Solve[D[f, x] == 0, x, Reals];
Print["Extremwerte: ", {Which[f2 > 0, "T", f2 < 0, "H", f2 == 0, "S" ], x,  
f} //. ew];
Print["Extremwerte: ", {If[f2 > 0, "T", "H" ], x, f} /. ew];
]


KD[x^3 - 3 x^2, -1, 4]

Prints:

Extremwerte: {{H,0,0},{T,2,-4}}
Extremwerte: {{H,0,0},{T,2,-4}}



  • Prev by Date: A basic question about RecurrenceTable - warning messages
  • Next by Date: count the number of sub-list in a list
  • Previous by thread: Re: Problem with "Which"
  • Next by thread: Re: Problem with "Which"