# Khan/khan-exercises

Sequences and series

Summary: TODO(alpert): Geometric series

Test Plan: Looked at them.

Reviewers: eater

Reviewed By: eater

Differential Revision: http://phabricator.khanacademy.org/D2044
1 parent 82e2bd3 commit 25bce65e3563398cf9a66708a9a19db87f46f788 spicyj committed Feb 15, 2013
36 exercises/arithmetic_sequences_1.html
 @@ -0,0 +1,36 @@ + + + + + Arithmetic sequences 1 + + + +
+
+
+
+ randRange(-10, 10) + randRangeNonZero(-6, 6) + randRange(3, 5) + _.map(_.range(N), function(i) { return A + i * D; }) +
+ +
+

The first cardinal(N) terms of an arithmetic sequence are given:

+

GIVEN.join(","), \ldots

+

What is the ordinal(N + 1) term in the sequence?

+
+
A + D * N
+ +
+

In any arithmetic sequence, each term is equal to the previous term plus the common difference.

+

Thus, the second term is equal to the first term plus the common difference. In this sequence, the second term, A + D, is abs(D) D > 0 ? "more" : "less" than the first term, A.

+

Therefore, the common difference is D.

+

The ordinal(N + 1) term in the sequence is equal to the ordinal(N) term plus the common difference, or A + D * (N - 1) + D = A + D * N.

+
+
+
+
+ +
62 exercises/arithmetic_sequences_2.html
 @@ -0,0 +1,62 @@ + + + + + Arithmetic sequences 2 + + + +
+
+
+
+ randRangeNonZero(-10, 10) + randFromArray([-1, 1]) * randRange(2, 6) + randRange(2, 20) +
+ +
+

The arithmetic sequence (a_i) is defined by the formula:

+

a_i = A + D(i - 1)

+

What is a_{N}, the ordinal(N) term in the sequence?

+
+
A + D * (N - 1)
+ +
+

From the given formula, we can see that the first term of the sequence is A and the common difference is D.

+
+

The second term is simply the first term plus the common difference.

+

Therefore, the second term is equal to a_2 = A + D = A + D.

+
+
+

To find a_{N}, we can simply substitute i = N into the given formula.

+

Therefore, the ordinal(N) term is equal to a_{N} = A + D (N - 1) = A + D * (N - 1).

+
+
+
+
+
+

+ a_1 = A
+ a_i = a_{i-1} + D
+

+
+ +
+

From the given formula, we can see that the first term of the sequence is A and the common difference is D.

+
+

The second term is simply the first term plus the common difference.

+

Therefore, the second term is equal to a_2 = a_1 + D = A + D = A + D.

+
+
+

To find the ordinal(N) term, we can rewrite the given recurrence as an explicit formula.

+

The general form for an arithmetic sequence is a_i = a_1 + d(i - 1). In this case, we have a_i = A + D(i - 1).

+

To find a_{N}, we can simply substitute i = N into the our formula.

+

Therefore, the ordinal(N) term is equal to a_{N} = A + D (N - 1) = A + D * (N - 1).

+
+
+
+
+
+ +
55 exercises/arithmetic_series.html
 @@ -0,0 +1,55 @@ + + + + + Arithmetic series + + + +
+
+
+
+ randRangeNonZero(-40, 40) + randFromArray([-1, 1]) * randRange(2, 6) + randRange(5, 20) + N * (2 * A + D * (N - 1)) / 2 +
+ +
+

The arithmetic sequence (a_i) is defined by the formula:

+

a_i = A + D(i - 1)

+

What is the sum of the first N < 10 ? cardinal(N) : N terms in the series?

+
+
SUM
+ +
+

The sum of an arithmetic series is the number of terms in the series times the average of the first and last terms.

+
+

To find the sum of the first N < 10 ? cardinal(N) : N terms, we'll need the first and ordinal(N) terms of the series.

+

The first term is A and the ordinal(N) term is equal to a_{N} = A + D (N - 1) = A + D * (N - 1).

+
+

Therefore, the sum of the first N < 10 ? cardinal(N) : N terms is

+

\qquad n\left(\dfrac{a_1 + a_{N}}{2}\right) = N \left(\dfrac{A + A + D * (N - 1)}{2}\right) = SUM. +

+
+
+
+
+

+ a_1 = A
+ a_i = a_{i-1} + D
+

+
+ +
+
+

First, let's find the explicit formula for the terms of the arithmetic series. We can see that the first term is A and the common difference is D.

+

Thus, the explicit formula for this sequence is a_i = A + D(i - 1).

+
+
+
+
+
+ +
51 exercises/geometric_sequences_1.html
 @@ -0,0 +1,51 @@ + + + + + Geometric sequences 1 + + + +
+
+
+
+ randRangeNonZero(-8, 8) + randFromArray([-1, 1]) * randRange(1, 4) + randRange(1, 4) + randRange(3, 5) + + randRange(-N - 1, 0) + _.map(_.range(N), function(i) { + if (i + OFFSET >= 0) { + return reduce(A * pow(RN, i + OFFSET), pow(RD, i + OFFSET)); + } else { + return reduce(A * pow(RD, -i - OFFSET), pow(RN, -i - OFFSET)); + } + }) + reduce(A * pow(RN, N + OFFSET), pow(RD, N + OFFSET)) + + fractionReduce(RN, RD) + _.map(GIVEN, function(f) { + return fractionReduce.apply(KhanUtil, f); + }) +
+ +
+

The first cardinal(N) terms of a geometric sequence are given:

+

GIVEN_TEX.join(","), \ldots

+

What is the ordinal(N + 1) term in the sequence?

+
+
A * pow(RN / RD, N + OFFSET)
+ +
+

In any geometric sequence, each term is equal to the previous term times the common ratio.

+

Thus, the second term is equal to the first term times the common ratio. In this sequence, the second term, GIVEN_TEX[1], is R_TEX times the first term, GIVEN_TEX[0].

+

Therefore, the common ratio is R_TEX.

+

The ordinal(N + 1) term in the sequence is equal to the ordinal(N) term times the common ratio, or GIVEN_TEX[N - 1] \cdot R_TEX = fractionReduce(A * pow(RN, N + OFFSET), pow(RD, N + OFFSET)).

+
+
+
+
+ +
76 exercises/geometric_sequences_2.html
 @@ -0,0 +1,76 @@ + + + + + Geometric sequences 2 + + + +
+
+
+
+ randRangeNonZero(-8, 8) + randFromArray([-1, 1]) * randRange(1, 4) + randRange(1, 4) + randRange(2, 5) + randRange(-N - 1, 0) + _.map(_.range(N), function(i) { + if (i + OFFSET >= 0) { + return reduce(A * pow(RN, i + OFFSET), pow(RD, i + OFFSET)); + } else { + return reduce(A * pow(RD, -i - OFFSET), pow(RN, -i - OFFSET)); + } + }) + + fractionReduce(RN, RD) + _.map(TERMS, function(f) { + return fractionReduce.apply(KhanUtil, f); + }) +
+ +
+

The geometric sequence (a_i) is defined by the formula:

+

a_i = TERMS_TEX[0] \left(R_TEX\right)^{i - 1}

+

What is a_{N}, the ordinal(N) term in the sequence?

+
+
A * pow(RN / RD, N - 1 + OFFSET)
+ +
+

From the given formula, we can see that the first term of the sequence is TERMS_TEX[0] and the common ratio is R_TEX.

+
+

The second term is simply the first term times the common ratio.

+

Therefore, the second term is equal to a_2 = TERMS_TEX[0] \cdot R_TEX = TERMS_TEX[1].

+
+
+

To find a_{N}, we can simply substitute i = N into the given formula.

+

Therefore, the ordinal(N) term is equal to a_{N} = TERMS_TEX[0] \left(R_TEX\right)^{N - 1} = TERMS_TEX[N-1].

+
+
+
+
+
+

+ a_1 = TERMS_TEX[0]
+ a_i = R_TEXa_{i-1} +

+
+ +
+

From the given formula, we can see that the first term of the sequence is TERMS_TEX[0] and the common ratio is R_TEX.

+
+

The second term is simply the first term times the common ratio.

+

Therefore, the second term is equal to a_2 = TERMS_TEX[0] \cdot R_TEX = TERMS_TEX[1].

+
+
+

To find the ordinal(N) term, we can rewrite the given recurrence as an explicit formula.

+

The general form for a geometric sequence is a_i = a_1 r^{i - 1}. In this case, we have a_i = TERMS_TEX[0] \left(R_TEX\right)^{i - 1}.

+

To find a_{N}, we can simply substitute i = N into the formula.

+

Therefore, the ordinal(N) term is equal to a_{N} = TERMS_TEX[0] \left(R_TEX\right)^{N - 1} = TERMS_TEX[N-1].

+
+
+
+
+
+ +
17 utils/math-format.js
 @@ -314,6 +314,23 @@ $.extend(KhanUtil, { return card.charAt(0).toUpperCase() + card.slice(1); }, + ordinal: function(n) { + if (n <= 9) { + return ["zeroth", "first", "second", "third", "fourth", "fifth", + "sixth", "seventh", "eighth", "ninth"][n]; + } else if (Math.floor(n / 10) % 10 === 1) { + // Teens + return n + "th"; + } else { + var lastDigit = n % 10; + if (1 <= lastDigit && lastDigit <= 3) { + return n + ["st", "nd", "rd"][lastDigit - 1]; + } else { + return n + "th"; + } + } + }, + // Depends on expressions.js for expression formatting // Returns a string with the expression for the formatted roots of the quadratic // with coefficients a, b, c 16 utils/tmpl.js  @@ -1,5 +1,7 @@ (function() { +var testMode; + // Keep the template variables private, to prevent external access var VARS = {}; @@ -15,7 +17,12 @@$.tmpl = { // False means all templating will be run again, so new values will be chosen var result = !!(ensure && $.tmpl.getVAR(ensure)); if (!result) { - ++$.tmpl.DATA_ENSURE_LOOPS; + if ($.tmpl.DATA_ENSURE_LOOPS++ > 10000 && testMode) { + // Shucks, probably not possible. Just give up in order + // to not hang the dev's browser. + alert("unsatisfiable data-ensure?"); + return true; + } } return result; }; @@ -320,9 +327,10 @@$.fn.tmplLoad = function(problem, info) { VARS = {}; $.tmpl.DATA_ENSURE_LOOPS = 0; - // Check to see if we're in test mode - if (info.testMode) { - // Expose the variables if we're in test mode + testMode = info.testMode; + + // Expose the variables if we're in local mode + if (testMode) {$.tmpl.VARS = VARS; } };