ITPEC FE Subject B April 2024 Question 16

From the answer group below, select the correct combination of answers to be inserted into A and B in the program.

The function m_sin calculates and returns the approximate value of sin(x) for the argument x using the Maclaurin expansion. The program calculates sin(x) using the approximate formula below:

sin(x) = x/1! - x3/3! + x5/5! - … + (-1)n × ( x(2n+1)/(2n+1)!)

Here, ! is the factorial symbol, and n is the first integer for which | x(2n+1) / (2n+1)! | ≤ 10-7 is satisfied.

[Program]
○ real: m_sin(real: x)
real: vn ← x
real: k ← 1
real: sum ← vn
real: epsi ← 1×10⁻⁷
while (abs(vn) A) // abs(vn) returns the absolute value of vn
k ← k + 2
vn ← B
sum ← sum + vn
endwhile
return sum

Answer group

OptionAB

Explanation

A: > epsi, B: - vn × x² ÷ ((k - 1) × k) — keep adding terms while they are larger than the tolerance, and build each term from the previous one.

k is the exponent of the current term: 1, 3, 5, and so on. After k ← k + 2 the new term is xk ÷ k! with the opposite sign. Since k! = (k - 2)! × (k - 1) × k and xk = xk - 2 × x2, the new term is the old one times -x2 ÷ ((k - 1) × k), which is blank B:

  • •k = 3: vn = -x × x2 ÷ (2 × 3) = -x3 ÷ 3!
  • •k = 5: vn = (-x3 ÷ 6) × (-x2) ÷ (4 × 5) = x5 ÷ 5!

The loop starts with vn = x and must continue while the latest term is still larger than the tolerance, abs(vn) > epsi (blank A). The first term whose absolute value is at most 10-7 is still added to sum, then the test fails, which matches the formula: its last term is the first one within the tolerance.

Answer (h)

Why not others:

  • •(a), (b), (c), (d) and (e) — A as ≤ epsi is false at the start for any x larger than 10-7 in absolute value, so the loop never runs and the function returns x itself
  • •(f) — B as - vn × x ÷ k multiplies by one x and one factor only: after x it gives -x2 ÷ 3, an even power
  • •(g) — B as - vn × x² ÷ k² divides by k2: the second term becomes -x3 ÷ 9 instead of -x3 ÷ 6
  • •(i) and (j) — B with xᵏ multiplies by the whole new power instead of x2, so the exponents run 1, 4, 9, 16 instead of 1, 3, 5, 7

Key rule: Sum a series by multiplying the previous term by the ratio of consecutive terms, and loop while the latest term still exceeds the tolerance.

Math & Numbers · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.