Formatting Functions To Avoid Loss Of Significant

104 Views Asked by At

Rewrite the following to avoid loss of significant

  1. $\ln(x+1)-\ln(x)$ where $x>>1$

  2. $\cos^2(x)-\sin^2(x)$ where $x\approx \frac{\pi}{4}$

  3. $\sqrt{x^2+1}-x$ where $x>>1$

  4. $\sqrt{\frac{1+\cos x}{2}}$

  1. Using taylor expansion we get $$x-\frac{x^2}{2}+\frac{x^3}{3}-[(x-1)-\frac{(x-1)^2}{2}+\frac{(x-1)^3}{3}]=1+\frac{(x-1)^2-x^2}{2}+\frac{x^3-(x-1)^3}{3}$$

  2. Using taylor expansion we get $$(1-\frac{x^2}{2!}+\frac{x^4}{4!})^2-(x-\frac{x^3}{3!}+\frac{x^5}{5!})^2$$

  3. $$\sqrt{x^2+1}-x=(\sqrt{x^2+1}-x)\cdot (\frac{\sqrt{x^2+1}+x}{\sqrt{x^2+1}+x})=\frac{1}{\sqrt{x^2+1}+x}$$

  4. $$\sqrt{\frac{1+\cos x}{x}}\approx \sqrt{\frac{1+1-\frac{x^2}{2!}+\frac{x^4}{4!}}{2}}$$

Is this valid?

2

There are 2 best solutions below

0
On

You don't want to use the Taylor series when $x$ is large. Better to use the law of exponents to write $\log(x+1) - \log (x)=\log(1+\frac 1x)$ and use the Taylor series from there.

This is the usual approach. You want to analytically subtract the large parts of the two numbers, reducing the cancellation.

2
On

You shouldn't use Taylor series for these.

  1. $\log(x+1)-\log(x) = \log(1+\frac{1}{x})$

  2. $\cos^2 x - \sin^2 x = \cos 2x$

  3. $\sqrt{x^2+1} - x = (\sqrt{x^2+1} - x) \frac{\sqrt{x^2+1}+x}{\sqrt{x^2+1}+x}$ and simplify.

  4. $1+\cos x = 2\cos^2 \frac{x}{2}$. This identity should help.