Re: Trying to use Table to iterate a Part specification
- To: mathgroup at smc.vnet.net
- Subject: [mg42579] Re: [mg42542] Trying to use Table to iterate a Part specification
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Wed, 16 Jul 2003 09:13:40 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 04:42 AM 7/14/2003, pi314159 wrote: >I'm trying to write a small program that will identify critical points >of functions with two independent variables. I'm using the >discriminant test to generate a list of the value of the discriminant >at each point; since If isn't listable (I think), and I couldn't get >Map to cooperate, I'm using Table to run the if-loop over each item in >the list of discriminant values ("signs"). However, I have to use a >Part specification to tell If which element in the list I want it to >use, and Part doesn't like Table's iterations. Is there a way around >this? > >Thanks! > >pi314159 > >--- > >criticalpoints[expr_] := Solve[{D[expr, x] == 0, D[expr, y] == 0}, {x, >y}]; > >discriminant[expr_] := D[expr, x, x]*D[expr, y, y] - D[expr, x, y]^2; > >identifycriticalpoints[expr_] := > Module[{signs, length1, points, points2}, > signs = discriminant[expr] /. criticalpoints[expr]; > length1 = Length[signs]; > points = criticalpoints[expr]; > points2 = > Partition[DeleteCases[Flatten[List @@@ Flatten[points]], >_Symbol], 2] > Table[ > If[Positive[Part[signs, i]] == True, > If[D[expr, x, x] > 0, Print["Minimum", Part[points2, i]], > Print["Maximum", Part[points2, i]]], > Print["Saddle point", Part[points2, i] > ], > {i, 1, length1}] > ]; > ] Your instinct to use Map was correct. Try the following: identifycriticalpoints[expr_] := Module[{length, points, results}, points = criticalpoints[expr]; points = Cases[Union[points], {_[_,_?NumericQ]...}]; length = Length[points]; results = {discriminant[expr], D[expr, x, x], x, y}/.points; Map[testresults, results]; ] testresults[{dis_, der_, x_, y_}]:= If[Positive[dis], If[Positive[der], Print["Minimum: ", {x,y}], Print["Maximum: ", {x,y}] ], Print["Saddle Point: ", {x,y}] ] -------------------------------------------------------------- Omega Consulting "The final answer to your Mathematica needs" http://omegaconsultinggroup.com