Math(Comp) 365/HW 2

Name: Hin Li

Problem 1

a)For cos(x), the Taylor exansion at x=0 would be \( \ \sum_{k=0}^{\infty} \frac{(-1)^k x^{2k}}{2k!} = 1+0- \frac{x^2}{2}+0 +\frac{x^4}{24} \)

the 5th degree would be \( 1- \frac{x^2}{2}+\frac{x^4}{24} \)

b)By using R,

error = function(x) {
    return(abs((cos(x) - (1 - (x^2)/2 + (x^4)/24))))
}
x = seq(-pi/4, pi/4, length = 1e+05)
bound = max(error(x))
print(bound)
## [1] 0.0003224

We get the upper bound to be about 0.00032.

c) The 2nd degree function should be f(x)=1, while the 4th degree should be \( f_4(x) \)=1-x2/2

P = function(x) {
    return(1 - x^2/2)
}
PP = function(x) {
    return(1 - x^2/2 + x^4/24)
}
x = seq(-2, 2, length = 2e+05)
plot(x, cos(x), type = "l", col = "black", xlim = c(-pi/2, pi/2), ylim = c(-1.5, 
    1.5))
lines(x, P(x), col = "blue")
lines(x, PP(x), col = "red")

plot of chunk unnamed-chunk-2

Problem 2

a) Let us consider the integer part of 11.25 first.

11=23+21+20

So, the binary code should be \( (1011)_2 \).

For the decimal part, 0.25=2-2, so the binary code should be .01

So, the overall code is \( (1011.01)_2 \)

b) For 2/3,

2/3*2=4/3 (drop 1 here)

1/3*2=2/3 (drop 0 here)

2/3*2=4/3 (drop 1 here, repeating the first step)

the overall binary code should be \( (0.1010101010......)_2 \)

c)For 99.9, the integer part is 99 and 99=26+25+21+20. So the binary code should be \( (1100011)_2 \). For the decimal part,

0.9*2=1.8

0.8*2=1.6

0.6*2=1.2

0.2*2=0.4

0.4*2=0.8

0.8*2=1.6, now this step is the same as the second step, so we get \( (.1110011001100...)_2 \)

so the overall binary code should be \( (1100011.1110011001100...)_2 \) where 1100 will repeat forever.

Problem 3

So the binary number for 7/3=\( (10.0101010101010101...)_2 \)

For 4/3=\( (1.0101010101010101...)_2 \)

For 1/3=\( (0.0101010101010101...)_2 \)

The IEEE expression for 7/3 is 1.0010101010101010101010101010101010101010101010101011*21

For 4/3, it is 1.0101010101010101010101010101010101010101010101010101*20

For 1/3, it is 1.0101010101010101010101010101010101010101010101010101*2−2

a)In machine expression,7/3-4/3=1.0000000000000000000000000000000000000000000000000001*20

so 7/3-4/3=1+machine epsilon.

b)No,4/3-1/3 is not machine epsilon, since in machine expression, 4/3-1/3=

0.111111111111111111111111111111111111111111111111111111*20

The answer would be rounded to 1 as the 53rd digit is 1.

Problem 4

We get 128.

The IEEE for 1e+18 is 1.1011110000010110110101100111010011101100100000000000*259

The IEEE for 100 is 1.1001000000000000000000000000000000000000000000000000*26

By adding them together, we get 110111100000101101101011001110100111011001000000000001.1001*26

which is equal to 1.101111000001011011010110011101001110110010000000000011001*259

By rounding up, we get 1.1011110000010110110101100111010011101100100000000001*259

which equals to 110111100000101101101011001110100111011001000000000010*26

Clearly, if we minus 1e+18 now, we will get \( (10)_2 \) x 26=128

Problem 5

The smallest positive number should be a number with a binary code of 54 digits.So it should be

1 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1

that is 253+1=9007199254740993.