Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to plot $a x^2 + b x + c$ where $a, b, c$ (and $x$) take on a range of values.

I tried

ParametricPlot[{x, a x^2 + b x + c}, {x, -1, 1},
               {a, -.25, .25}, {b, -.25, .25}, {c, -.25, .25}]

but ParametricPlot can only handle up to two parameters.

My work around uses FindInstance which can be really slow:

RangePlot[eq_Equal, {x_, xmin_, xmax_}, {y_, ymin_, ymax_}, vars_List, constraints_] := 
    RegionPlot[
        FindInstance[And[constraints, eq], vars] =!= {}, {x, xmin, xmax}, {y, ymin, ymax}
    ]

RangePlot[y == a x^2 + b x + c, {x, -1, 1}, {y, -1, 1}, {a, b, c}, 
    -.25 < a < .25 && -.25 < b < .25 && -.25 < c < .25]

result of RangePlot[]

Is there a better way to do this?

share|improve this question
    
This is not quite what I'm looking for. I want a,b,c,x to all take on a non-discrete amount of values. That is to say a,b,c,x all take on a range of values in some interval. –  Chip Hurst Oct 21 '12 at 3:34
1  
A bit hard to visualize things when you have four things varying all at once. Maybe take three at a time and fix one of those parameters? –  J. M. Oct 21 '12 at 4:17
2  
@J.M. I thought the same at first, but re reading the question the Op wants the coverage of $R^2$ obtained by the whole parameters' range. Much more interesting –  belisarius Oct 21 '12 at 4:26

3 Answers 3

One can observe that your parabola is a monotonic function of a and c, therefore one can define a minimum and maximum family of parabolas as :

minPar = a x^2 + b x + c /. {a -> -1/4, c -> -1/4};
maxPar = a x^2 + b x + c /. {a -> 1/4, c -> 1/4};

Next, one can pick the very maximum and minimum of the family :

minMinPar[x_] := Piecewise[{{minPar /. b -> 1/4, x <= 0}, {minPar /. b -> -1/4, x > 0}}]
maxMaxPar[x_] := Piecewise[{{maxPar /. b -> -1/4, x <= 0}, {maxPar /. b -> 1/4, x > 0}}]

and assuming continuity one can then just plot the two extreme curves and fill in between :

Plot[{minMinPar[x], maxMaxPar[x]}, {x, -1, 1}, Filling -> {1 -> {2}}]

enter image description here

share|improve this answer

Reduce can solve this problem. First, reduce the inequalities to a cylindrical decomposition in which the inequalities for x and y are in the first two "levels" or "dimensions" (not the same as Mathematica levels -- I'm not sure if there is a standard name). Delete the inequalities related to the parameters. Reduce again, if you want the result simplified.

xyineq = DeleteCases[
   Reduce[y == a x^2 + b x + c && -1 < x < 1 && -1 < 4 a < 1 && -1 < 
      4 b < 1 && -1 < 4 c < 1, {x, y, a, b, c}, Reals], 
   ineq : (_Inequality | _Less | _Equal) /; MemberQ[ineq, a | b | c, Infinity],
   Infinity];

xyrgn = Reduce[xyineq, {x, y}, Reals]
(*
  (-1 < x <= 0 &&  1/4 (-1 + x - x^2) < y < 1/4 (1 - x + x^2)) ||
  ( 0 < x < 1  &&  1/4 (-1 - x - x^2) < y < 1/4 (1 + x + x^2))
*)

RegionPlot[xyrgn, {x, -1, 1}, {y, -0.75, 0.75}]

Mathematica graphics

share|improve this answer

This is a solution which I am using currently, as an alternative for 2D ParametricPlot with more than 2 variables. (I am not claiming anything regarding it being optimal - it just solves my purpose)

The simple way out is to discretize the range of the variables into fine grid and evaluate the functions at that point (hence there is a constant predicatable overhead of the computation time, using which you can discretize the grid)

For this example here I am using the function objFn which is dependent on 3 variables g1,g2 and g3

points = Partition[
   Flatten@Table[{g1, g2, g3}, {g1, 1, 3, 0.1}, {g2, 1, 3, 0.1}, {g3, 
      1, 3, 0.1}], 3];
fPoints = objFn @@ # & /@ points
ListPlot[fPoints]

You get a pixelated image from which you can make out the region. But is more predicatable , in terms of computation time it takes, than using FindInstance

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.