Determining The Matlab Output

  • #1
260
21
Homework Statement
We are required to explain the values of g(x) and h(x).

The script for Matlab is:
g = @(x) (exp(x)-1-x)./x.^2;
h = @(x) (exp(x)-x-1)./x.^2;
x = 1e-10;
fprintf(’x=%.16e\ng(x)=%.16e\nh(x)=%.16e\n’, x, g(x), h(x))
x = 2^(-33);
fprintf(’x=%.16e\ng(x)=%.16e\nh(x)=%.16e\n’, x, g(x), h(x))

The output is:
x=1.0000000000000000e-10
g(x)=8.2740370962658164e+02
h(x)=0.0000000000000000e+00
x=1.1641532182693481e-10
g(x)=0.0000000000000000e+00
h(x)=0.0000000000000000e+00
Relevant Equations
-
I am having a bit of trouble understanding what the values of g(x) and h(x) mean. I went through it by hand and here is information that I gathered about the values and questions I am trying to answer to gain a better understanding. Firstly, for the value of x=1e-10 both the numerator of g(x) and the numerator of h(x) equate to the same number on my calculator and of course they have the same denominator, but then I don't understand why g(x) equals a positive number whereas h(x) equals 0, does this all just come from the error? I get the answer I am expecting for g(x) but not h(x).

Secondly, when I calculate g(x) for x=2-33 I get a negative number and when I calculate h(x) when x=2-33 I get 0. But why would the output for g(x) be 0 on MATLAB but when I calculate it I obtain a negative number? Is this simply only due to the precision of using 16 decimals whereas on my calculator it's much less?

Any help would be appreciated, thanks.
 
  • #2
I went through it by hand ... equate to the same number on my calculator
Working it out on your calculator is not going through it by hand.

does this all just come from the error? ... Is this simply only due to the precision of using 16 decimals whereas on my calculator it's much less?
This question is all about the impact of the order of operations on roundoff error.
 
  • Like
Likes ver_mathstats and DrClaude

Suggested for: Determining The Matlab Output

Replies
5
Views
553
Replies
3
Views
562
Replies
5
Views
831
Replies
3
Views
536
Replies
10
Views
887
Replies
2
Views
628
Replies
1
Views
574
Replies
12
Views
1K
Back
Top