We got two (identical) functions given
$$f(x) = \sqrt{x^2+1}-1$$
$$g(x)=\frac{x^2}{\sqrt{x^2+1}+1}$$
Calculate the function $f(x)$ and $g(x)$ for each $x=\frac{1}{2^i}, i=1,...,25$ using a program of your choice (so we don't need to do it by hand). Do it once with single and once with double precision floating-point format and compare the results with each other.
So my question is about the
Calculate the function $f(x)$ and $g(x)$ for each $x=\frac{1}{2^i}, i=1,...,25$
So let me make an example for $x=1: f(1) = \sqrt{1^2+1}-1= \sqrt{2}-1$
Now they want this in single and double precision floating point format, correct?
And then I do the same for $x=2,...25$, right?
And then my other question
compare the results with each other
Do I compare single and double precision results or compare results of $f(x)$ and $g(x)$?
I hope you can clarify it for me, the teacher just ignored my question as it seems :(
No, that's not what it says. It says do the same for $i=2\ldots 25$ for $x=\frac{1}{2^i}$. So $1/2$, $1/4$, etc. The smaller your number grows, the more important the errors in floating point arithmetic will become.
This makes it sound as if the entire point of the exercise is to compare the floating point results, so as to see how different expressions can accumulate error differently.
There is no point in comparing the "actual" results because we already know they will be identical.