Linear Equations Package

Kenneth M. Levasseur
Department of Mathematical Sciences
University of Massachusetts Lowell
Lowell, MA 01854
Kenneth_Levasseur@uml.edu

This notebook is accompanied by an autoload package (LinearEquations.m) that is automatically updated when this notebook is edited.  LinearEquations.m is the file that is loaded upon evaluation of
	Needs["LinearEquations`"] 
or 
	<<LinearEquations`
The advantage to having this .nb file is that it is easier to keep it organized.

Important note:  the cells that you want to be part of the package should be Initialization Cells (Input Style cells with the Initialization property set to True)

What you will see below is the recommended way to structure a context.

Start

Comments and Declaration of the LinearEquations` context.

\(\( (*\  : Title : \ LinearEquations\ *) 

     (*\  : Author : Ken\ Levasseur\ *) 

     (*\  : Summary : \ 

          Package\ with\ various\ functions\ relating\ to\ linear\ equations\ 
            in\ two\ \(variables.\)
*) 

     (*\  : Package\ \(Version : \ 1.0\)\ *) 

     (*\  : Copyright : \ Copyright\ 1998\ Ken\ Levasseur*) 

     (*\  : Context : LinearEquations`\ *) 

     (*\  : History : \ \ V1  .0\ \ October\ 1998*) 

     (*\  : \(Keywords : \)\ *) 
 (*\  : Limitation : ?\ *) 

     (*\  : \(Discussion : \)\ *) 

BeginPackage["LinearEquations`"]

    \)\)

Usage/Other Messages

Declaration of the Names that are part of the LinearEquations` context.   It is customary to do this through usage statements.

Usage

\(x::usage = "x is the independent variable for lines."; 


    y::usage\  = \ "y is the dependent variable for lines."; 


    EquationOfLine::usage = 
      "EquationOfLine[a,b] returns the equation of the line relating variables x and y where a and b are either 

		a slope and intercept

		a slope and point  or 

		two points point and point.
"; 


    PlotLine::usage\  = 
      "PlotLine is an option of EquationOfLine that controls whether 

a plot of the line represented by an equation is diplayed."; 


    YIntercept::usage = 
      "YIntercept[line] is the y-intercept of line. Takes the form of a point {0,b}."; 


    XIntercept::usage = 
      "XIntercept[line] is the x-intercept of line.   Takes the form of a point {a,0}"; 


    StandardFormOfLine::usage = 
      "StandardFormOfLine[line] returns the standard form of line."; \)

Other Messages

\(EquationOfLine::notunique = 
      "Two identical points do not define a unique line.  Horizontal line is chosen as the result."; 

    YIntercept::VerticalLine = "Line is vertical - no y -intercept."\)XIntercept::HorizontalLine = 
      "Line is horizontal - no x -intercept."

Private

After the expression Begin["`Private`"], any name that is not declared to be in the LinearEquations Context and is not in the System context will be consider to be in the LinearEquations`Private Context.  See notes on Contexts for the significance of private contexts.

 In order to be able to set the default value of the option PlotLine, we use an auxilliary function called EOL.  EOL is defined within this private context to determine equations of lines and supplies the result to the "public" function EquationOfLine.

\(\(
Begin["`Private`"]; 


    Options[EquationOfLine] = {PlotLine -> False}; 

     (*The\ following\ definitions\ for\ EOL\ are\ copied\ from\ the\ previous
        \ definitions\ for\ EquationOfLine*) 

    EOL[m_, b_] := \((y == m\ x\  + b)\); 


    EOL[m_, {s_, t_}] := Simplify[\((y - t)\) == m \((x - s)\)]; 


    EOL[{s_, t_}, {u_, v_}] := EOL[\((\((v - t)\)/\((u - s)\))\), {s, t}]; 

    
EOL[{s_, t_}, {s_, v_}] := \((x == s)\); 


    EOL[{s_, t_}, {s_, t_}] := 
	
      \((Message[EquationOfLine::notunique]; 
		\ y == t)\); 


    EquationOfLine[a_, b_, opts___?OptionQ] := 
	
      Module[{plotQ = PlotLine /. Flatten[{{opts}, Options[EquationOfLine]}], 
          equation}, 
		equation = EOL[a, b]; 
		
        If[plotQ, yexpression = y /. First[Solve[equation, y]]; 
          Plot[yexpression, {x, \(-10\), 10}, 
            PlotRange -> {{\(-10\), 10}, {\(-10\), 10}}]]; 
		equation]; 

    
YIntercept[eq_] := 
      If[FreeQ[eq, \ y], 
        Message[YIntercept::VerticalLine], {0, 
          y /. First[Solve[eq /. {x -> 0}, y]
]}]; 


    XIntercept[eq_] := 
      If[FreeQ[eq, \ x], 
        Message[XIntercept::HorizontalLine], {
          x /. First[Solve[eq /. {y -> 0}, x]
], 0}]; 


    StandardFormOfLine[eq_] := 
	
      If[\ \((\((a = XIntercept[eq])\) =!= Null)\) && 
          \((\((b = YIntercept[eq])\) =!= Null)\), 
		
        x/First[a]\  + \ y/Last[b]\  == 1, eq]; \)\)

End

Finish the process of creating LinearEquations and its Private context.

\(\(End[]; 
EndPackage[]; 
\)\)