# Calculating error of the approximate formula in calculations

I have an exact equation:

$$a = \sqrt{1 + x^2 - \sqrt{(1 + x^2)^2 - 2 x^2 \cos^2\theta}}\tag{1}$$

and its approximation:

$$a = \dfrac{x \cos^2\theta}{\sqrt{1 + x^2}}\tag{2}$$

I'm doing most theoretical calculations using equation $(2)$ and to check the outcomes I'm doing numerical calculations of $(1)$ in Mathematica.

For example, finding $\left.\frac{da}{dx}\right|_{x = 0}$ dividing by $\left.\frac{da}{d\theta}\right|_{\theta = 0}$ and integrating:

$$\int\limits_{0}^{A}\frac{\left.\frac{da}{dx}\right|_{\theta = 0}}{\left.\frac{da}{d\theta}\right|_{\theta = 0}}dx$$

And I want to check that this (or any other) procedure doesn't differ much from the same for precise and approximate function.

How can I verify that the use of the approximate formula doesn't make the calculations inaccurate?

-
A slightly more accurate approximation might be had by using $\dfrac{x\cos\theta}{\sqrt{1+x^2}}$ $\dfrac1{1-\left(\frac{x\cos\theta}{2(1+x^2)}\right)^2}$... –  Ｊ. Ｍ. Nov 25 '12 at 9:45
$\dfrac{x\lvert\cos\theta\rvert}{\sqrt{1+x^2}}$ seems to be pretty good to me. –  Rahul Nov 25 '12 at 11:01
Looks more like a math question. –  Jens Nov 25 '12 at 21:40

I don't understand how you get your approximate expression. I'd do a series expansion of your expression and check how well it approximates it :

exact2[x_, y_] = Sqrt[1 + x^2] Sqrt[1 - Sqrt[1 - 2 (y/(1 + x^2))^2]];

Simplify[exact2[x, x Cos[\[Theta]]],  Assumptions -> {x \[Element] Reals, \[Theta] \[Element] Reals}] ==
Simplify[exact[x, \[Theta]], Assumptions -> {x \[Element] Reals, \[Theta] \[Element] Reals}]

(* True *)

appr[x_, \[Theta]_] = Simplify[Normal[Series[exact2[x, y], {y, 0, 2}]],
Assumptions -> {x \[Element] Reals}] /. y -> (x Cos[\[Theta]])

(* (x Cos[\[Theta]])/Sqrt[1 + x^2] *)


You can check how well the approximation is valid for $x \cos(\theta) \approx 0$ :

RegionPlot[Abs[exact[x, \[Theta]] - appr[x, \[Theta]]] < 0.001, {x, -5, 5}, {\[Theta], -\[Pi], \[Pi]} ,
FrameTicks -> {Automatic, {-\[Pi]/2, \[Pi]/2}}, FrameLabel -> {"x", "\[Theta]"}, PlotPoints -> 50]]


-
exact[x_, \[Theta]_] :=
Sqrt[1 + x^2 - Sqrt[(1 + x^2)^2 - 2 x^2 Cos[\[Theta]]^2]]
approximate[x_, \[Theta]_] := x Cos[\[Theta]]^2/Sqrt[1 + x^2]


I'm not sure what kind of verification you want, or what your values are, but you could make a plot to get an idea (now with relative error as @J.M suggested)

absoluteError[x_, \[Theta]_] :=
exact[x, \[Theta]] - approximate[x, \[Theta]]
relativeError[x_, \[Theta]_] :=
1 - approximate[x, \[Theta]]/exact[x, \[Theta]] // Abs

Plot3D[absoluteError[x, \[Theta]], {x, -0.2, 0.2}, {\[Theta], -Pi, Pi},
AxesLabel -> (Style[#, 20] & /@ {"x", "\[Theta]"})]


Plot3D[relativeError[x, \[Theta]], {x, -0.02, 0.2}, {\[Theta], -Pi,
Pi}, AxesLabel -> (Style[#, 20] & /@ {"x", "\[Theta]"}),
PlotRange -> {0., 0.2}]


-
I've updated the question. I think this is now much easier to understand. –  m0nhawk Nov 25 '12 at 9:10
One might also consider looking at the relative error in addition to the absolute error... –  Ｊ. Ｍ. Nov 25 '12 at 9:37