solving third order equation: bad result

• To: mathgroup at smc.vnet.net
• Subject: [mg22152] solving third order equation: bad result
• From: "Wolter Kaper" <kaper at chem.uva.nl>
• Date: Wed, 16 Feb 2000 02:35:18 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Dear Mathgroup members,

When I solve the following equation for V, in terms of symbolic P and then
substitute a value for P, I get a result that is wrong. (The right result is
returned when I solve the equation with P substituted beforehand.)

P == RT /(V - b) - a/V^2 /. {a -> 0.142666, b -> 3.913*10^(-5), RT -> 2494})

The following notebook demonstrates the problem and compares results after
the equation has been rewritten in standard (third order polynomial ==0)
form. In that case the right result is returned.
My questions are: does anybody know why this behaviour occurs, has anybody
seen it before, should I report a bug to Wolfram research?

Thanks beforehand,
Wolter Kaper
Univ. Of Amsterdam, dept. of Chemistry

Notebook follows.

(***********************************************************************

Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of
the following:

* Save the data starting with the line of stars above into a file
with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the
word CacheID, otherwise Mathematica-compatible applications may try to
use invalid cache data.

applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info at wolfram.com
phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)

(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      5727,        190]*)
(*NotebookOutlinePosition[      6380,        213]*)
(*  CellTagsIndexPosition[      6336,        209]*)
(*WindowFrame->Normal*)

Notebook[{

Cell[CellGroupData[{
Cell["Faulty / inaccurate solution", "Title"],

Cell["W.H. Kaper (kaper at chem.uva.nl)", "Subtitle"],

Cell[TextData[{
StyleBox["Problem:",
FontWeight->"Bold"],
" When I solve the following equation for V, in terms of symbolic P and \
then substitute a value for P, I get a result that is wrong. The right
result \
is returned when I solve the equation with P substituted beforehand."
}], "Text"],

Cell[BoxData[
\(Remove["\<Global`*\>"]\)], "Input"],

Cell[CellGroupData[{

Cell[BoxData[
\(eq1 =
P == T\/\(V - b\) - a\/V\^2 /. {a \[Rule] \ 0.142666,
b \[Rule] \ 3.913*10^\(-5\), T \[Rule] \ 2494}\)], "Input"],

Cell[BoxData[
\(P == 2494\/\(\(-0.00003913`\) + V\) - 0.142666`\/V\^2\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
\(OplA = Solve[eq1, \ V]\)], "Input"],

Cell[BoxData[
\({{V \[Rule] \(-\(\(6.6666666666666664`*^-15\ \((\(-1.247`*^17\) -
1.9565`*^9\ P)\)\)\/P\)\)}, {V \[Rule] \
\(-\(\(6.6666666666666664`*^-15\ \((\(-1.247`*^17\) -
1.9565`*^9\ P)\)\)\/P\)\)}, {V \[Rule] \
\(-\(\(6.6666666666666664`*^-15\ \((\(-1.247`*^17\) -
1.9565`*^9\ P)\)\)\/P\)\)}}\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
\(OplA /. P \[Rule] 4*10^8\)], "Input"],

Cell[BoxData[
\({{V \[Rule] 0.000015121666666666666`}, {V \[Rule]
0.000015121666666666666`}, {V \[Rule]
0.000015121666666666666`}}\)], "Output"]
}, Open  ]],

Cell["This is wrong. (physical considerations)", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
\(eq2 = eq1\  /. P \[Rule] 4*10^8\)], "Input"],

Cell[BoxData[
\(400000000 ==
2494\/\(\(-0.00003913`\) + V\) - 0.142666`\/V\^2\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
\(Solve[eq2, \ V]\)], "Input"],

Cell[BoxData[
\({{V \[Rule]
4.774318802122206`*^-7 -
0.000017720931948096697`\ \[ImaginaryI]}, {V \[Rule]
4.774318802122206`*^-7 +
0.000017720931948096697`\ \[ImaginaryI]}, {V \[Rule]
0.00004441013623957556`}}\)], "Output"]
}, Open  ]],

Cell["\<\
These solutions are OK. None of them is equal to the faulty 0.0000151217.\
\>", "Text"],

Cell["\<\
As a comparison, I can also rewrite eq1 in standard \"third order \
polynomial\" form:\
\>", "Text"],

Cell[CellGroupData[{

Cell[BoxData[
\(eq3 =
P*V^3 - \((T + P*b)\)*V^2\  + \ a*V\  - \ a*b \[Equal]
0 /. {a \[Rule] \ 0.142666, b \[Rule] \ 3.913*10^\(-5\),
T \[Rule] \ 2494}\)], "Input"],

Cell[BoxData[
\(\(-5.582520579999999`*^-6\) +
0.142666`\ V - \((2494 + 0.00003913`\ P)\)\ V\^2 + P\ V\^3 ==
0\)], "Output"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
\(\(OplB = Solve[eq3, \ V];\)\)], "Input"],

Cell[BoxData[
\(General::"spell1" \(\(:\)\(\ \)\)
"Possible spelling error: new symbol name \"\!\(OplB\)\" is similar to
\
existing symbol \"\!\(OplA\)\"."\)], "Message"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
\(OplB /. P \[Rule] 4*10^8\)], "Input"],

Cell[BoxData[
\({{V \[Rule]
4.774318802122236`*^-7 -
0.000017720931948096676`\ \[ImaginaryI]}, {V \[Rule]
4.774318802122236`*^-7 +
0.000017720931948096676`\ \[ImaginaryI]}, {V \[Rule]
0.000044410136239575546`}}\)], "Output"]
}, Open  ]],

Cell[TextData[{
"Now it works allright, even when I leave P symbolic and only substitute \
afterwards.\n",
StyleBox["So my question is",
FontWeight->"Bold"],
": why does the deviating solution \"0.0000151217\" appear? Is it a matter
\
of limited numerical accuracy? \nAnd why does \"Solve\" come up with three \
solutions that are identical? I know that a cubic equation has three \
(complex) roots, but apparently \"Solve\" has not used the general routine \
for solving a cubic equation, because then it should have arrived at the \
result presented last."
}], "Text"]
}, Open  ]]
},
FrontEndVersion->"4.0 for Microsoft Windows",
ScreenRectangle->{{0, 800}, {0, 527}},
WindowSize->{497, 431},
WindowMargins->{{19, Automatic}, {Automatic, 0}}
]

(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of
the file.  The cache data will then be recreated when you save this file
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{

Cell[CellGroupData[{
Cell[1739, 51, 45, 0, 150, "Title"],
Cell[1787, 53, 50, 0, 64, "Subtitle"],
Cell[1840, 55, 301, 6, 71, "Text"],
Cell[2144, 63, 55, 1, 30, "Input"],

Cell[CellGroupData[{
Cell[2224, 68, 157, 3, 63, "Input"],
Cell[2384, 73, 87, 1, 42, "Output"]
}, Open  ]],

Cell[CellGroupData[{
Cell[2508, 79, 55, 1, 30, "Input"],
Cell[2566, 82, 386, 6, 119, "Output"]
}, Open  ]],

Cell[CellGroupData[{
Cell[2989, 93, 57, 1, 30, "Input"],
Cell[3049, 96, 170, 3, 48, "Output"]
}, Open  ]],
Cell[3234, 102, 56, 0, 33, "Text"],

Cell[CellGroupData[{
Cell[3315, 106, 64, 1, 30, "Input"],
Cell[3382, 109, 102, 2, 42, "Output"]
}, Open  ]],

Cell[CellGroupData[{
Cell[3521, 116, 48, 1, 30, "Input"],
Cell[3572, 119, 286, 6, 48, "Output"]
}, Open  ]],
Cell[3873, 128, 97, 2, 33, "Text"],
Cell[3973, 132, 110, 3, 33, "Text"],

Cell[CellGroupData[{
Cell[4108, 139, 197, 4, 50, "Input"],
Cell[4308, 145, 143, 3, 48, "Output"]
}, Open  ]],

Cell[CellGroupData[{
Cell[4488, 153, 60, 1, 30, "Input"],
Cell[4551, 156, 181, 3, 60, "Message"]
}, Open  ]],

Cell[CellGroupData[{
Cell[4769, 164, 57, 1, 30, "Input"],
Cell[4829, 167, 287, 6, 48, "Output"]
}, Open  ]],
Cell[5131, 176, 580, 11, 128, "Text"]
}, Open  ]]
}
]
*)

(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)

```

• Prev by Date: letter
• Next by Date: Animation