W2 Tute2
W2 Tute2
Solution:
a. Since 𝑥 = , we have 𝑥 = = =1+ =1+
( )± ( ) ∙ ∙( ) ±√
Solving for 𝑥: 𝑥 = =
∙
The Fibonacci sequence has all positive terms so all by definition of 𝑥 , 𝑥 ≥ 0 for all 𝑛 ≥ 0.
√
So, 𝑥 = .
√ √
b. Let 𝐹 = − .
√
√ √
𝑘 = 0: 𝐹 = − = [1 − 1] = 0
√ √
√ √ √ √ √
𝑘 = 1: 𝐹 = − = = =1
√ √ √
√ √ √ ( √ ) √
𝑘 = 2: 𝐹 = − = = =1
√ √ √
√ √
For ease of computing, let 𝑢 = and 𝑣 = . Then you can write 𝐹 = [𝑢 − 𝑣 ]
√
Consider
1 1
𝐹 +𝐹 = [𝑢 −𝑣 ]+ [𝑢 − 𝑣 ]
√5 √5
1
= [𝑢 +𝑢 −𝑣 −𝑣 ]
√5
1 1 1 1 1
= 𝑢 + −𝑣 +
√5 𝑢 𝑢 𝑣 𝑣
1 1 1 1 1
= 𝑢 + −𝑣 +
√5 𝑢 𝑢 𝑣 𝑣
1
= [𝑢 −𝑣 ]
√5
=𝐹
b. lim sin =0
→
( ) ⋯
Consider −1 = −1 = 1− + −⋯ −1 = − +⋯
( )
So, = 1 + 𝑂(ℎ )
So, 1 − cos 𝑥 = − +⋯
( ) ⋯
Consider −0 = = − +⋯
( )
So, = 𝑂(ℎ)
4. Construct an algorithm that has as input an integer 𝑛 ≥ 1, numbers 𝑥 , 𝑥 , … , 𝑥 , and a number 𝑥 and that
produces as output the product (𝑥 − 𝑥 )(𝑥 − 𝑥 ) ∙∙∙ (𝑥 − 𝑥 ).
Solution:
INPUT: 𝑛, 𝑥, 𝑥 , 𝑥 , … , 𝑥
OUTPUT: 𝑝𝑟𝑜𝑑
𝑎𝑏
b. Modify this sum expression to an equivalent form that reduces the number of computations.
Solution:
Since 𝑖 = 1: 𝑛,
( )
we have the total number of multiplications = ∑ (𝑖) =
( )
Similarly, for the inner sum, we need total number of additions = ∑ (𝑖 − 1) =
Then we need another (n-1) additions to add these sums together.
( ) ( ) ( ) ( )( )
So, total number of additions = +𝑛−1 = =
Example:
∗ ∗
For 𝑛 = 1, we have just = 1 multiplication and = 0 additions. (𝑎 𝑏 )
∗ ∗
For 𝑛 = 2, we have = 3 multiplications and = 2 addition. (𝑎 𝑏 + 𝑎 𝑏 + 𝑎 𝑏 )
∗ ∗
For 𝑛 = 3, we have = 6 multiplications and = 5 additions (𝑎 𝑏 + 𝑎 𝑏 + 𝑎 𝑏 + 𝑎 𝑏 + 𝑎 𝑏 + 𝑎 𝑏 )
𝑎𝑏 = 𝑎 𝑏
For each 𝑖, ∑ 𝑏 will have (𝑖 − 1) additions. 𝑎 ∑ 𝑏 will add on just 1 multiplication to the term
(∑ 𝑏 ).
So, total number of multiplications = ∑ (1) = 𝑛
( )( )
Total number of additions = (∑ (𝑖 − 1)) + (𝑛 − 1) =
6. Assume that,
1 − 2𝑥 2𝑥 − 4𝑥 4𝑥 − 8𝑥 1 + 2𝑥
+ + +⋯= for 𝑥 < 1, and let 𝑥 = 0.025.
1−𝑥+𝑥 1−𝑥 +𝑥 1−𝑥 +𝑥 1+𝑥+𝑥
Write and execute an algorithm that determines the number of terms needed on the left side of the equation so
that the left side differs from the right side by less than 10 .
7. Let 𝑓(𝑥) = (𝑥 + 2)(𝑥 + 1 ) 𝑥(𝑥 − 1 ) (𝑥 − 2). To which zero of 𝑓 does the Bisection method converge when
applied on the following intervals?
a. [−1.5, 2.5]
b. [−0.5, 2.4]
c. [−0.5, 3]
d. [−3, −0.5]
Solution:
a. 0
b. 0
c. 2
d. -2
Use algorithm to see which zero it converges to. The possible zeroes are -2, -1, 0, 1, or 2.
Solution:
9. Let 𝑓(𝑥) = (𝑥 − 1) , 𝑝 = 1, and 𝑝 = 1 + . Show that |𝑓(𝑝 )| < 10 whenever 𝑛 > 1 but that |𝑝 − 𝑝 | <
10 requires that 𝑛 > 1000.
Solution:
For 𝑛 > 1, |𝑓(𝑝 )| = 1+ −1 = = ≤ = < 10
1 1
|𝑝 − 𝑝 | = 1 − 1 − = < 10 ⟹ 𝑛 > 10 = 1000
𝑛 𝑛
10. A trough of length L has a cross section in the shape of a semicircle with radius r. When filled with water to
within a distance h of the top, the volume V of water is given by:
Suppose 𝐿 = 10 𝑓𝑡, 𝑟 = 1 𝑓𝑡, and 𝑉 = 12.4 𝑓𝑡 . Find the depth of water in the trough to within 0.01 𝑓𝑡.
Solu on:
Solve for the equa on 𝑉 − 𝐿 0.5𝜋𝑟 − 𝑟 𝑎𝑟𝑐𝑠𝑖𝑛 ℎ 𝑟 − ℎ(𝑟 − ℎ ) = 0 for h.
Itera on 1: a = 0.000000, p = 0.500000, b = 1.000000
Itera on 2: a = 0.000000, p = 0.250000, b = 0.500000
Itera on 3: a = 0.000000, p = 0.125000, b = 0.250000
Itera on 4: a = 0.125000, p = 0.187500, b = 0.250000
Itera on 5: a = 0.125000, p = 0.156250, b = 0.187500
Itera on 6: a = 0.156250, p = 0.171875, b = 0.187500
Itera on 7: a = 0.156250, p = 0.164062, b = 0.171875
Itera on 8: a = 0.164062, p = 0.167969, b = 0.171875
11. Create an octave func on to find the root of a func on given the interval the root exists in.
% If max_iterations is reached and the root is not found within the tolerance
warning('Maximum number of iterations reached. The root may not be found within the desired tolerance.');
root = p;
endfunction
To use this func on, you can run the following script: