1
$\begingroup$

enter image description here


As you can see here, the question is about part b. By using Matlab, the answer to the part a is -2.4, but by using "format long" to compute directly, the answer is -2.401923018799901, which I don't think the cancellation is catastrophic.

Bty, I tried to put rewrite it to 1/x - sqrt(1/x^2 + 5/x), while the answer is -2.4 as well.

I am also not confident with my rewriting, please show me if you have any better rewritings.

Thanks a lot.

$\endgroup$
11
  • 1
    $\begingroup$ In "base 10, precision 2 floating point" we don't get $-2.401923018799901$ but rather $-2.35$ (note that all computations should use only 2 significant figures)! $\endgroup$
    – Winther
    Sep 16, 2014 at 22:51
  • $\begingroup$ @Winther Thanks for your comment. When I do this in Matlab, I used digits(2) and then used vpa() to perform "precision 2 floating point". Could you tell me how to do it correctly in Matlab? thanks $\endgroup$
    – JasonHu
    Sep 16, 2014 at 22:57
  • $\begingroup$ I don't know, but it's easy enough to do by hand: $1+5x = 1.17$ and $\sqrt{1.17} = 1.08167 \to 1.08$ so $1-\sqrt{1+5x} = -0.08$ and finally $(1-\sqrt{1+5x})/x=-0.08/0.034 = -2.35294 \to -2.35$. $\endgroup$
    – Winther
    Sep 16, 2014 at 23:01
  • $\begingroup$ @Winther Thank you, I'll try to figure it out. Really thank you for your calculation by hand. $\endgroup$
    – JasonHu
    Sep 16, 2014 at 23:03
  • $\begingroup$ btw about significant figures see here. So I think you might need digits(3) in MatLab?! $\endgroup$
    – Winther
    Sep 16, 2014 at 23:03

3 Answers 3

1
$\begingroup$

One way to rewrite the expression is to multiply by the conjugate:

$$\frac{1 - \sqrt{1 + 5x}}{x} \cdot \frac{1 + \sqrt{1 + 5x}}{1 + \sqrt{1 + 5x}} = \frac{1 - (1 + 5x)}{x(1 + \sqrt{1 + 5x})} = -\frac{5}{1 + \sqrt{1 + 5x}}$$

For this second expression, when $x \sim 0$ the denominator is $\sim 2$, and you get a number close to $-5/2$. In the original expression when $x \sim 0$ both the numerator and denominator are close to zero so you could get problems.

But it doesn't actually seem like you got any problems in your computation, so...?

$\endgroup$
0
$\begingroup$

I think the right rewriting is

$-\frac{5}{1+\sqrt{1+5x}} $

obtained by multiplication for $1+\sqrt{1+5x}$.

You usually have a cancellation with the sign minus when the result is very close to zero, so it's convenient use a rewriting where it doesn't appear

$\endgroup$
1
  • $\begingroup$ @genisage edited $\endgroup$
    – Exodd
    Sep 16, 2014 at 22:45
0
$\begingroup$

The trick here is to avoid the subtraction cancellation through multiplying numerator and denominator by the conjugate radical:

$$ \frac{1 - \sqrt{1+5x}}{x} = \frac{1 - (1+5x)}{x(1+\sqrt{1+5x})} = \frac{-5}{1+\sqrt{1+5x}} $$

Give that a try.


Here's what happens if you evaluate the original expression in 2 decimal digit floating point precision:

$$ x = 0.034 $$

$$ 5x \approx 0.17 $$

$$ 1 + 5x \approx 1.2 $$

$$ \sqrt{1+5x} \approx 1.1 $$

$$ 1 - \sqrt{1+5x} \approx -0.1 \; \text{ NB: subtractive cancellation }$$

$$ \frac{1 - \sqrt{1+5x}}{x} \approx -2.9 $$

So there's a significant loss of precision in doing it this way.

$\endgroup$
8
  • $\begingroup$ Thank you for your answer and with precision 2, the answer is -2.4 as well, and after part a and part b, the part c of this question is to compute relative errors in previous two parts but in this case, it's meaningless. Are there anything wrong with my performance? Thanks $\endgroup$
    – JasonHu
    Sep 16, 2014 at 22:53
  • $\begingroup$ @JasonHu: If you compute the intermediate expressions with two significant digits, you will not get -2.4. Perhaps you are computing the expression with high precision intermediate values, then doing one final rounding at the end. That's not what the exercise calls for. $\endgroup$
    – hardmath
    Sep 16, 2014 at 23:04
  • $\begingroup$ Do you know how to process this in Matlab? I used vpa() function with digits(2) and I think vpa do the precision 2 for every calculation it contains, not just the final answer. $\endgroup$
    – JasonHu
    Sep 16, 2014 at 23:21
  • $\begingroup$ Then write them out on separate lines, storing in separate variables if need be, and see if the Answer is the same. Or do it by hand on a sheet of paper, as I just did, and be done with it. $\endgroup$
    – hardmath
    Sep 16, 2014 at 23:23
  • $\begingroup$ I did it step by step and you are right, the answer is -2.9. Thanks. Do you know any appropriate function to use in matlab? $\endgroup$
    – JasonHu
    Sep 16, 2014 at 23:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .