Parabola Plotter

Marion Harding

1994 Mathematica Workshop

By definition, a parabola is the set of all points in a plane that are the same distance from a fixed point and a fixed line in the plane.  The fixed point, F, is the focus, and the fixed line, l, is the directrix of the parabola.

The following code illustrates the equal distance from the parabola to the focus and to the directrix.  First, the graph of y = 10x¤ is shown with the focus and directrix.  Then the equal distance is illustrated.

Clear[f,x,a,p1,focus];
f[x_] = 10x^2
p1=Plot[{-1/40,f[x]},{x,-7,7},
	     PlotStyle->{{RGBColor[0,1,0],Thickness[0.015]},
	                 {RGBColor[0,0,1],Thickness[0.01]}},
	     PlotRange->{{-.5,.5},{-.5,.5}},
	     AspectRatio->1,
	     DisplayFunction->Identity];
focus=Graphics[{PointSize[0.025],RGBColor[0,1,0],Point[{0,1/40}]}];
Show[p1,focus,DisplayFunction->$DisplayFunction];

Do[pt=Graphics[{PointSize[0.04],RGBColor[0,0,1],Point[{t,f[t]}]}];
   line1=Graphics[Line[{{t,f[t]},{t,-1/40}}]];
   line2=Graphics[Line[{{t,f[t]},{0,1/40}}]];  
   labels=Graphics[{Text[FontForm["F",{"Courier-Bold",12}], 
   {0.03,0.05}],
      	            Text[FontForm["d",{"Courier-Bold",12}], 
      	            {0.1,-0.05}],
      	            Text["(x,f(x))",{t+0.04,f[t]+0.04}]}];
   distf=N[Sqrt[t^2 + (f[t]-1/40)^2],3];
   distd=N[(f[t] + 1/40),3];
   distances=Graphics[{Text[FontForm["Distance to F = ",
   {"Courier-Bold",12}],{0.3,-0.25},{1,0}],
     	          Text[FontForm[distf,{"Courier-Bold",12}],
     	           {0.3,-0.25}, {-1,0}],
     	          Text[FontForm["Distance to d = ",
     	          {"Courier-Bold",12}], {0.3,-0.3}, {1,0}],
     	          Text[FontForm[distd,{"Courier-Bold",12}], 
     	          {0.3,-0.3}, {-1,0}]}];
   Show[p1,line1,line2,focus,pt,labels,distances,
   DisplayFunction->$DisplayFunction],
   {t,-0.2,0.2,0.05}]

The following code finds the focus and the directrix of any parabola.  One can enter the coefficients, a, b, and c, and produce a graph showing the focus and directrix.  Entering the same a, b, and c again, the vertex, focus, and directrix are given.  (Some comments about the code are included.)

Clear[a,b,c,vy,vx,p1,focus]

(*This program graphs a parabola, its
      focus, and its directrix with any 
      a, b, and c. To enter a, b, c, 
      type Parabolamaker[] and enter.*) 

Parabolamaker[]:=

Module[{a,b,c,vy,vx,p1,focus,f},

a=Input["Enter in a"];
b=Input["Enter in b"];
c=Input["Enter in c"];

f[x_] = a x^2 + b x + c;

vx = -b/(2 a);

vy = a (vx)^2 + b (vx) + c;
(*This graphs the directrix*)
p1=
Plot[

(* The If statement takes the first argument if true,
 and the second argument if false*)
  
{If[a>0,

	vy - Abs[1/(4a)],
	vy + Abs[1/(4a)]],
	
 	f[x]},

(*The domain is one unit each side of the vertex*)

{x,vx-1,vx+1},
	PlotLabel->StringForm["y = ``",f[x]],
 PlotStyle->{{RGBColor[0,1,0],Thickness[0.015]},
	                 {RGBColor[0,0,1],Thickness[0.01]}},
 
 (*The range is 3/Abs[4a] above and below the vertex*)
 
 PlotRange->{vy - 3/Abs[4a],vy + 3/Abs[4a]}, AspectRatio->1,
 DisplayFunction->Identity];
	     
focus=
Graphics[{PointSize[0.025],RGBColor[0,1,0],
If[a>0,Point[{vx,vy+1/(4 a)}],Point[{vx,vy-Abs[1/(4 a)]}]]}];


Show[p1,focus,DisplayFunction->$DisplayFunction];


]; (*the Module Parabola maker ends*)

coef[a_,b_,c_]:=

(vx=-b/(2a);
	vy=a (-b/(2 a))^2 + b (-b/(2 a)) + c;


Print[StringForm["The vertex is: ``.  The focus is: ``.
\n The directrix is: y = \n``",
{vx,vy},
If[a>0,{vx,vy+1/(4 a)},{vx,vy-Abs[1/(4 a)]}],
If[a>0,	vy - Abs[1/(4a)],vy + Abs[1/(4a)]]
]
]
)

Enter in the following code to plot any parabola . . .

Parabolamaker[]

To find the vertex, focus, and directrix for the graph, enter the same a, b, c as above in the following:

coef[-1,3,2]

Do these results agree with the graph?  If not, compare the coefficients to see if you entered them correctly.