Exploring Analyic Geometry with Mathematica®

Home Contents Commands Packages Explorations Reference
Tour Lines Circles Conics Analysis Tangents

D2DSolve2D

The package D2DSolve2D provides the Solve2D function which is a specialized version of the Mathematica Solve and NSolve commands.

Initialization

BeginPackage["D2DSolve2D`", {"D2DExpressions2D`"}];

D2DSolve2D::usage=
   "D2DSolve2D is a package for solving equations.";

MaxSeconds2D::usage=
   "MaxSeconds2D is an option of the Solve2D function that time constrains the solution of the equations.";

Solve2D::usage=
   "Solve2D[eqns,vars] solves a list of equations for variables in given in a list.";

Options[Solve2D]=
   {MaxSeconds2D->30};

Begin["`Private`"];

Symbol Queries

Single Symbol Query

The private function IsSymbol$2D[expr,symbol] returns True if the expression contains a given symbol; otherwise, returns False.

IsSymbol$2D[expr_,sym_Symbol] := MemberQ[Level[expr,{-1}],sym];

Symbol List Query

The private function IsSymbol$2D[expr,symbolList] returns True if the expression contains any of the symbols in a list; otherwise, returns False.

IsSymbol$2D[expr_,sym_List] := Or @@ Map[IsSymbol$2D[expr,#]&,sym];

Solve

Maximum Seconds Option

Format: MaxSeconds2D->n
The option MaxSeconds2D specifies the maximum number of seconds allowed to solve equations using Solve2D.  The private function AskMaxSeconds$2D returns the current setting for MaxSeconds2D.

Solve2D::invalidTime=
   "Option MaxSeconds2D->`1` is invalid; 'MaxSeconds2D' must be positive; the current value of MaxSeconds2D->`2` will be retained.";

protected=Unprotect[SetOptions];
SetOptions[Solve2D,opts1___,MaxSeconds2D->n_,opts2___] :=
   Message[Solve2D::invalidTime,n,AskMaxSeconds$2D[ ]] /;
(IsZeroOrNegative2D[n] || !IsReal2D[n]);
Protect[Evaluate[protected]];

AskMaxSeconds$2D[ ] := Options[Solve2D,MaxSeconds2D][[1,2]];

Solve

Format: Solve2D[eqnList,varsList,opts]
Solves a list of equations for a list of variables.  Uses the Mathematica function NSolve if any Real numbers are involved, or if N[_] is in the evaluation stack; otherwise, uses the Mathematica function Solve.  An empty list is returned (and a warning message output) if the equations cannot be solved in the number of seconds specified by the option MaxSeconds2D->n.

Solve2D::infinite=
   "An infinite number of solutions exist; only independent solutions will be returned.";

Solve2D::time=
   "The equations could not be solved in MaxSeconds2D->`1`, an empty list of solutions will be returned; using approximate numbers may produce a more complete list of solutions.";

SimplifyEquation$2D[eqn_Equal] :=
   (eqn[[1]]//ExpandAll)==(eqn[[2]]//ExpandAll);

Solve2D[eqns:{HoldPattern[Equal[_,_]..]},
        vars:{_Symbol..},
        MaxSeconds2D->secs_] :=
   Module[{save,result},
      save=AskMaxSeconds$2D[ ];
      SetOptions[Solve2D,MaxSeconds2D->secs];
      result=Solve2D[eqns,vars];
      SetOptions[Solve2D,MaxSeconds2D->save];
      result ];

Solve2D[eqns:{HoldPattern[Equal[_,_]..]},vars:{_Symbol..}] :=
   Module[{save,ans},
      save=Head[Solve::svars];Off[Solve::svars];
      ans=TimeConstrained[
          If[IsApproximate2D[eqns],
             NSolve[Map[SimplifyEquation$2D,eqns]//N,vars,
                    WorkingPrecision->$MachinePrecision],
             Solve[Map[SimplifyEquation$2D,eqns],vars]],
          AskMaxSeconds$2D[ ],
          Message[Solve2D::time,AskMaxSeconds$2D[ ]];{}];
      If[save===String,On[Solve::svars]];
      If[IsSymbol$2D[Map[(vars /. #)&,ans],vars],
         Message[Solve2D::infinite];
         Select[ans,Not[IsSymbol$2D[(vars /. #),vars]]&],
         ans] ];

Epilogue

End[ ]; (* end of "`Private" *)
EndPackage[ ]; (* end of "D2DSolve2D`" *)


Copyright © 1999-2007 Donald L. Vossler, Descarta2D Publishing
www.Descarta2D.com