MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Differentiation and Polynomial questions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20718] Re: Differentiation and Polynomial questions
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 10 Nov 1999 00:17:37 -0500
  • References: <805vjq$ddu@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Danny:

Answers to you first two questions are in the following notebook.
To see it properly formatted,
-- copy from "Notebook" down to the final "]" (just short of the line of
stars)
-- open up a Mathematica Notebook
-- past into the notebook
( a new notebook will be generated from the copied code)

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565



Notebook[{

Cell[CellGroupData[{
Cell["Step by Step Differentiation", "Subtitle"],

Cell[TextData[{
  "As you note,  ",
  Cell[BoxData[
      RowBox[{"RunD", "[",
        RowBox[{
          FractionBox[
            RowBox[{"f", "[", "x", "]"}],
            RowBox[{"g", "[", "x", "]"}]], ",", "x"}], "]"}]]],
  ",  gives the same as the built-in function:"
}], "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    RowBox[{"D", "[",
      RowBox[{
        RowBox[{
          RowBox[{"f", "[", "x", "]"}], "/",
          RowBox[{"g", "[", "x", "]"}]}], ",", "x"}], "]"}]], "Input"],

Cell[BoxData[
    RowBox[{
      FractionBox[
        RowBox[{
          SuperscriptBox["f", "\[Prime]",
            MultilineFunction->None], "[", "x", "]"}],
        RowBox[{"g", "[", "x", "]"}]], "-",
      FractionBox[
        RowBox[{
          RowBox[{"f", "[", "x", "]"}], " ",
          RowBox[{
            SuperscriptBox["g", "\[Prime]",
              MultilineFunction->None], "[", "x", "]"}]}],
        SuperscriptBox[
          RowBox[{"g", "[", "x", "]"}], "2"]]}]], "Output"]
}, Open  ]],

Cell["You want", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    RowBox[{"%", "file://", "Together", "  ",
      StyleBox[
        RowBox[{"(*",
          RowBox[{
          "quicker", " ", "for", " ", "this", " ", "than", " ",
"Simplify"}],
          "*)"}],
        FontWeight->"Plain"]}]], "Input"],

Cell[BoxData[
    FractionBox[
      RowBox[{
        RowBox[{
          RowBox[{"g", "[", "x", "]"}], " ",
          RowBox[{
            SuperscriptBox["f", "\[Prime]",
              MultilineFunction->None], "[", "x", "]"}]}], "-",
        RowBox[{
          RowBox[{"f", "[", "x", "]"}], " ",
          RowBox[{
            SuperscriptBox["g", "\[Prime]",
              MultilineFunction->None], "[", "x", "]"}]}]}],
      SuperscriptBox[
        RowBox[{"g", "[", "x", "]"}], "2"]]], "Output"]
}, Open  ]],

Cell["\<\
We can change the code of (a copy of)  Step by Step Differentiation to give
\
what you want as follow;\
\>", "Text"],

Cell["(1) Change", "Text"],

Cell[BoxData[
    RowBox[{
      RowBox[{"RuleNames", "=",
        RowBox[{"{", "\n", "\t\t",
          RowBox[{
          "\"\<SpecificRules\>\"", ",", "\n", "\t\t",
"\"\<ConstantRule\>\"",
            ",", "\n", "\t\t", "\"\<LinearityRule\>\"", ",", "\n", "\t\t",
            "\"\<PowerRule\>\"", ",", "\n", "\t\t", "\"\<ProductRule\>\"",
            ",", "\n", "\t\t", "\"\<QuotientRule\>\"", ",", "\n", "\t\t",
            "\"\<InverseFunctionRule\>\"", ",", "\n", "\t\t",
            "\"\<ChainRule\>\""}], "\n", "\t\t\t", "}"}]}], ";"}]],
"Input"],

Cell["\<\
so that \"QuotientRule\" comes before, and so is used before, \
\"ProductRule\", thus:\
\>", "Text"],

Cell[BoxData[
    RowBox[{
      RowBox[{"RuleNames", "=",
        RowBox[{"{", "\n", "\t\t",
          RowBox[{
          "\"\<SpecificRules\>\"", ",", "\n", "\t\t",
"\"\<ConstantRule\>\"",
            ",", "\n", "\t\t", "\"\<LinearityRule\>\"", ",", "\n", "\t\t",
            "\"\<PowerRule\>\"", ",", "\[IndentingNewLine]", "\t ",
            "\"\<QuotientRule\>\"", ",", "\n", "\t\t",
"\"\<ProductRule\>\"",
            ",", "\n", "\t\t", "\"\<InverseFunctionRule\>\"", ",", "\n",
            "\t\t", "\"\<ChainRule\>\""}], "\n", "\t\t\t", "}"}]}],
      ";"}]], "Input"],

Cell["(2) at the end of", "Text"],

Cell[BoxData[
    RowBox[{
      RowBox[{"WalkD", "[",
        RowBox[{"f_", ",", "x_"}], "]"}], ":=",
      RowBox[{"Module", "[",
        RowBox[{
          RowBox[{"{", "derivative", "}"}], ",",
          RowBox[{
            RowBox[{"derivative", "=",
              RowBox[{"d", "[",
                RowBox[{"f", ",", "x"}], "]"}]}], ";", "\n", "\t\t",
            RowBox[{"displayStart", "[", "derivative", "]"}], ";", "\n",
            "\t\t",
            RowBox[{"While", "[", "\[InvisibleSpace]",
              RowBox[{
                RowBox[{"!",
                  RowBox[{"(",
                    RowBox[{"FreeQ", "[",
                      RowBox[{"derivative", ",", "d"}], "]"}], ")"}]}], ",",
                "\n", "\t\t\t",
                RowBox[{
                  RowBox[{"oldderivative", "=", "derivative"}], ";",
                  RowBox[{"k", "=", "0"}], ";", "\n", "\t\t\t",
                  RowBox[{"While", "[",
                    RowBox[{
                      RowBox[{"oldderivative", "==", "derivative"}], ",",
                      "\n", "\t\t\t\t",
                      RowBox[{
                        RowBox[{"k", "++"}], ";", "\n", "\t\t\t\t",
                        RowBox[{"derivative", "=",
                          RowBox[{"derivative", "/.",
                            RowBox[{
                            "ListRules", "\[LeftDoubleBracket]", "k",
                              "\[RightDoubleBracket]"}]}]}]}]}], "]"}], ";",
                  RowBox[{"displayRuleUsed", "[",
                    RowBox[{
                    "RuleNames", "\[LeftDoubleBracket]", "k",
                      "\[RightDoubleBracket]"}], "]"}], ";", "\n", "\t\t\t",
                  RowBox[{"displayDerivative", "[", "derivative", "]"}]}]}],
              "]"}], ";", "\n", "\t\t",
            RowBox[{
              SubscriptBox["\[PartialD]", "x"], "f"}]}]}],
        "]"}]}]], "Input"],

Cell[TextData[{
  "Change ",
  Cell[BoxData[
      RowBox[{
        SubscriptBox["\[PartialD]", "x"], "f"}]]],
  " to ",
  StyleBox["derivative", "Input",
    FontWeight->"Plain"],
  "\nThis is needed because  the output from the given WalkD is not the \
result of the earlier steps but is the freshly computed output from  D[f,x]"
}], "Text"],

Cell[" 3) Change RunD similarly", "Text"],

Cell["\<\

Now load the new code.
We get\
\>", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    RowBox[{"WalkD", "[",
      RowBox[{
        RowBox[{
          RowBox[{"f", "[", "x", "]"}], "/",
          RowBox[{"g", "[", "x", "]"}]}], ",", "x"}], "]"}]], "Input"],

Cell[BoxData[
    RowBox[{"d", "[",
      RowBox[{
        FractionBox[
          RowBox[{"f", "[", "x", "]"}],
          RowBox[{"g", "[", "x", "]"}]], ",", "x"}], "]"}]], "Output",
  CellFrame->{{0, 0}, {0, 3}},
  CellMargins->{{Inherited, Inherited}, {0, Inherited}},
  CellEditDuplicate->False,
  CellGroupingRules->"OutputGrouping",
  FontWeight->"Bold",
  Background->RGBColor[0.8, 1, 0.8]],

Cell[BoxData["QuotientRule"], "Output",
  CellFrame->False,
  CellMargins->{{Inherited, Inherited}, {0, 0}},
  CellEditDuplicate->False,
  CellFrameMargins->{{100, Inherited}, {0, 0}},
  FontWeight->"Bold",
  FontSlant->"Italic",
  FontColor->RGBColor[0.6, 0, 0.6],
  Background->RGBColor[0.8, 1, 0.8]],

Cell[BoxData[
    RowBox[{
      InterpretationBox["=",
        Sequence[ ]], "    ",
      FractionBox[
        RowBox[{
          RowBox[{
            RowBox[{"-",
              RowBox[{"d", "[",
                RowBox[{
                  RowBox[{"g", "[", "x", "]"}], ",", "x"}], "]"}]}], " ",
            RowBox[{"f", "[", "x", "]"}]}], "+",
          RowBox[{
            RowBox[{"d", "[",
              RowBox[{
                RowBox[{"f", "[", "x", "]"}], ",", "x"}], "]"}], " ",
            RowBox[{"g", "[", "x", "]"}]}]}],
        SuperscriptBox[
          RowBox[{"g", "[", "x", "]"}], "2"]]}]], "Output",
  CellFrame->False,
  CellMargins->{{Inherited, Inherited}, {0, 0}},
  CellEditDuplicate->False,
  Evaluatable->False,
  FontWeight->"Bold",
  Background->RGBColor[0.8, 1, 0.8]],

Cell[BoxData["SpecificRules"], "Output",
  CellFrame->False,
  CellMargins->{{Inherited, Inherited}, {0, 0}},
  CellEditDuplicate->False,
  CellFrameMargins->{{100, Inherited}, {0, 0}},
  FontWeight->"Bold",
  FontSlant->"Italic",
  FontColor->RGBColor[0.6, 0, 0.6],
  Background->RGBColor[0.8, 1, 0.8]],

Cell[BoxData[
    RowBox[{
      InterpretationBox["=",
        Sequence[ ]], "    ",
      FractionBox[
        RowBox[{
          RowBox[{
            RowBox[{"g", "[", "x", "]"}], " ",
            RowBox[{
              SuperscriptBox["f", "\[Prime]",
                MultilineFunction->None], "[", "x", "]"}]}], "-",
          RowBox[{
            RowBox[{"f", "[", "x", "]"}], " ",
            RowBox[{
              SuperscriptBox["g", "\[Prime]",
                MultilineFunction->None], "[", "x", "]"}]}]}],
        SuperscriptBox[
          RowBox[{"g", "[", "x", "]"}], "2"]]}]], "Output",
  CellFrame->False,
  CellMargins->{{Inherited, Inherited}, {0, 0}},
  CellEditDuplicate->False,
  Evaluatable->False,
  FontWeight->"Bold",
  Background->RGBColor[0.8, 1, 0.8]],

Cell[BoxData[
    FractionBox[
      RowBox[{
        RowBox[{
          RowBox[{"g", "[", "x", "]"}], " ",
          RowBox[{
            SuperscriptBox["f", "\[Prime]",
              MultilineFunction->None], "[", "x", "]"}]}], "-",
        RowBox[{
          RowBox[{"f", "[", "x", "]"}], " ",
          RowBox[{
            SuperscriptBox["g", "\[Prime]",
              MultilineFunction->None], "[", "x", "]"}]}]}],
      SuperscriptBox[
        RowBox[{"g", "[", "x", "]"}], "2"]]], "Output"]
}, Open  ]],

Cell[TextData[{
  "WARNING: there may  have been a reason for the original ordering of ",
  StyleBox["RuleNames", "Input",
    FontWeight->"Plain"],
  ", so look out."
}], "Text"]
}, Open  ]],

Cell[CellGroupData[{

Cell["Ordering of polynomials", "Subtitle"],

Cell["We have the reordering", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
    RowBox[{
      RowBox[{"a", " ",
        RowBox[{"x", "^", "2"}]}], " ", "+", " ",
      RowBox[{"b", " ", "x"}], " ", "+", " ", "c"}]], "Input"],

Cell[BoxData[
    RowBox[{"c", "+",
      RowBox[{"b", " ", "x"}], "+",
      RowBox[{"a", " ",
        SuperscriptBox["x", "2"]}]}]], "Output"]
}, Open  ]],

Cell[TextData[{
  "If you select the output cell and then the menu item ",
  StyleBox["Cell > Convert To > TraditionalForm", "Input",
    FontWeight->"Plain"],
  StyleBox[" then you will get", "Input",
    FontFamily->"Times",
    FontWeight->"Plain"]
}], "Text"],

Cell[BoxData[
    FormBox[
      RowBox[{
        RowBox[{"c", " ",
          SuperscriptBox["x", "2"]}], "+",
        RowBox[{"b", " ", "x"}], "+", "a"}], TraditionalForm]], "Output"],

Cell["\<\
Alternatively, if you want to have all the output in traditional form then \
you can use the menu item Cell > Default Output Format Type >
TraditionalForm\
\
\>", "Text"]
}, Open  ]]
},
FrontEndVersion->"4.0 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 979}},
WindowSize->{496, 740},
WindowMargins->{{44, Automatic}, {Automatic, 104}}
]

********************************************************************

Danny Mathews <dmathews at ticnet.com> wrote in message
news:805vjq$ddu at smc.vnet.net...
> I was using the "StepbyStepDifferentiation" package I found on the web
site
> and it has raised a question for me.
>
> It seems that Mathematica ignores the Quotient Rule in general and uses
the
> Product Rule for equations in a f(x)/g(x) format.
>
> This leaves the solution in a f(x) + g(x) format that I have to simplify
to
> get the answer to agree with what I came up with using a pencil or on my
> TI-89 calculator.
>
> An example is (1+x^2)/(1-x^2).  I came up with(as did my TI-89)
> 4x/((x^2-1)^2) for a solution.
>
> Mathematica gives a answer in the form of f(x) + g(x) that will simplify
to
> the solution above.  I tried several examples with the same scenario.  Is
> there something I can do about this?
>
> Also, Mathematica displays polynomials with the powers written in
ascending
> order which is opposite of how I was taught to write polynomials in
standard
> form.  Can this be changed?
>
> Bonus Question:
>
> My Calculus instructor loves piece-wise functions.  Any info on plotting
> them would be helpful.
>
> Regards,
> Danny Mathews
>
>
>



  • Prev by Date: Three D Cellular automata notebooks for windows
  • Next by Date: Re: ContourPlot3D
  • Previous by thread: Differentiation and Polynomial questions
  • Next by thread: Re: Differentiation and Polynomial questions