Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge https://github.com/Khan/khan-exercises

  • Loading branch information...
commit 346c6d9ec32bc693407d3537d5e876748b4be9a0 2 parents 21f62d7 + 4c9cd87
elizabethslavitt authored November 28, 2011
120  exercises/lhopitals_rule.html
... ...
@@ -0,0 +1,120 @@
  1
+<!DOCTYPE html>
  2
+<html data-require="math math-format calculus polynomials expressions">
  3
+<head>
  4
+	<meta charset="UTF-8" />
  5
+	<title>L'Hopital's Rule</title>
  6
+	<script src="../khan-exercise.js"></script>
  7
+</head>
  8
+<body>
  9
+	<div class="exercise">
  10
+		<div class="problems">
  11
+			<div id="polynomial">
  12
+				<div class="vars">
  13
+					<var id="APPROACHES">randFromArray([ 0, Infinity ])</var>
  14
+					<var id="APPROACHES_TEXT">{ 0: "0", Infinity: "\\infty" }[ APPROACHES ]</var>
  15
+					<var id="INDETERMINATE_FORM">"\\frac" + { 0: "{0}{0}", Infinity: "{\\infty}{\\infty}" }[ APPROACHES ]</var>
  16
+
  17
+					<!-- Generate polynomials suitable for an L'Hopital's rule
  18
+					problem (has no plain numbers, requires taking no more
  19
+					than 3 derivatives to solve) -->
  20
+					<var id="DEGREE">KhanUtil.randRange( 2, 3 )</var>
  21
+					<var id="NUMERATOR">new KhanUtil.Polynomial( DEGREE - 1, DEGREE, KhanUtil.randCoefs( DEGREE - 1, DEGREE ), "x" )</var>
  22
+
  23
+					<!-- In order for an x->0 problem to be solvable with
  24
+					L'Hopital's rule, the denominator's minDegree must match the
  25
+					numerator's, but in an x->infinity problem, the maxDegree
  26
+					must match the numerator's -->
  27
+					<var id="DENOMINATOR" data-ensure="APPROACHES === 0 ? DENOMINATOR.findMinDegree() === NUMERATOR.findMinDegree() : DENOMINATOR.findMaxDegree() === NUMERATOR.findMaxDegree()">
  28
+						new KhanUtil.Polynomial( DEGREE - 1, DEGREE, KhanUtil.randCoefs( DEGREE - 1, DEGREE ), "x" )
  29
+					</var>
  30
+
  31
+					<!-- Find a list of successive derivatives of a polynomial
  32
+					until resolving an indeterminate form is possible. This
  33
+					is required for hints and to find the actual solution -->
  34
+					<var id="STEPS">
  35
+						(function() {
  36
+							var steps = [[ NUMERATOR, DENOMINATOR ]];
  37
+							var n = NUMERATOR, d = DENOMINATOR;
  38
+
  39
+							// In an x approaches zero problem we only care when
  40
+							// minDegree is 0 (i.e. there is a plain number
  41
+							// in the denominator so we can evaluate the expression),
  42
+							// in an approaches infinity problem we want maxDegree to be
  43
+							// 0 as well
  44
+
  45
+							while ( d.findMinDegree() !== 0 || ( APPROACHES === 0 ? false : d.findMaxDegree() !== 0 ) ) {
  46
+								n = KhanUtil.ddxPolynomial( n );
  47
+								d = KhanUtil.ddxPolynomial( d );
  48
+								steps.push([ n, d ]);
  49
+							}
  50
+
  51
+							return steps;
  52
+						})()
  53
+					</var>
  54
+
  55
+					<var id="SLN_NUMERATOR_TEXT">STEPS[ STEPS.length - 1 ][ 0 ]</var>
  56
+					<var id="SLN_DENOMINATOR_TEXT">STEPS[ STEPS.length - 1 ][ 1 ]</var>
  57
+
  58
+					<!-- The values of the actual solution -->
  59
+					<var id="SLN_NUMERATOR">SLN_NUMERATOR_TEXT.evalOf( 0 )</var>
  60
+					<var id="SLN_DENOMINATOR">SLN_DENOMINATOR_TEXT.evalOf( 0 )</var>
  61
+					<var id="SLN_SIMPLIFIES">reduces( SLN_NUMERATOR, SLN_DENOMINATOR ) || SLN_NUMERATOR &lt; 0 || SLN_DENOMINATOR &lt; 0 || abs( SLN_DENOMINATOR ) === 1</var>
  62
+				</div>
  63
+
  64
+				<div>
  65
+					<!-- Pose question as limit problem. Will look something like this: lim(x->0) (x)/(3x) = ? -->
  66
+					<p class="question">
  67
+						<code>\displaystyle \lim_{x \to <var>APPROACHES_TEXT</var>} \frac{<var>NUMERATOR</var>}{<var>DENOMINATOR</var>} = {?}</code>
  68
+					</p>
  69
+
  70
+					<p class="solution" data-type="rational"><var>SLN_NUMERATOR / SLN_DENOMINATOR</var></p>
  71
+				</div>
  72
+
  73
+				<div class="hints">
  74
+					<!-- Remind them of L'Hopital's rule -->
  75
+					<p>L'Hopital's rule states that since evaluating
  76
+						<!-- Original problem -->
  77
+						<code>\displaystyle \lim_{x \to <var>APPROACHES_TEXT</var>} \frac{<var>NUMERATOR</var>}{<var>DENOMINATOR</var>} = <var>INDETERMINATE_FORM</var></code>,<br />
  78
+						<!-- Explanation of rule -->
  79
+						if <code>\displaystyle \lim_{x \to <var>APPROACHES_TEXT</var>} \frac{\frac{d}{dx} (<var>NUMERATOR</var>)}{\frac{d}{dx} (<var>DENOMINATOR</var>)}</code> exists, evaluating it will give us the actual limit.
  80
+					</p>
  81
+
  82
+					<!-- Show them the steps of L'Hopital's rule by deriving until the indeterminate form can be resolved -->
  83
+					<p>
  84
+						Repeat this process until evaluating the limit will not result in an indeterminate form:<br />
  85
+						<span data-each="STEPS as N, STEP">
  86
+							<span data-if="N !== STEPS.length - 1">
  87
+								<code>
  88
+									\displaystyle\frac{\frac{d}{dx} (<var>STEP[0]</var>)}{\frac{d}{dx} (<var>STEP[1]</var>)} =
  89
+									\frac{<var>STEPS[N+1][0]</var>}{<var>STEPS[N+1][1]</var>}
  90
+								</code>
  91
+								<br />
  92
+								<span data-if="N + 1 !== STEPS.length - 1">
  93
+									<br />Since evaluating the limit at this point still results in <code><var>INDETERMINATE_FORM</var></code>, we must apply L'Hopital's rule again:<br />
  94
+								</span>
  95
+							</span>
  96
+						</span>
  97
+					</p>
  98
+
  99
+					<!-- Evaluate the limit and give the solution in both unsimplified and simplified form (if necessary) -->
  100
+					<p>
  101
+						<!-- Restate the problem using the derived, but unevaluated limit-->
  102
+						Evaluate the limit:
  103
+						<code>
  104
+							\displaystyle \lim_{x \to <var>APPROACHES_TEXT</var>} \frac{<var>SLN_NUMERATOR_TEXT.text()</var>}{<var>SLN_DENOMINATOR_TEXT.text()</var>}
  105
+							<!-- Show the evaluation of the limit (only necessary for x->0, otherwise evaluation is obvious because all variables will be gone) -->
  106
+							<span data-if="APPROACHES === 0">
  107
+								= \frac{<var>SLN_NUMERATOR_TEXT.text().replace("x", "(0)")</var>}{<var>SLN_DENOMINATOR_TEXT.text().replace("x", "(0)")</var>} =
  108
+								<!-- Give the unsimplified answer -->
  109
+								\frac{<var>SLN_NUMERATOR</var>}{<var>SLN_DENOMINATOR</var>}
  110
+							</span>
  111
+							<!-- Give the simplified answer, if necessary -->
  112
+							<span data-if="SLN_SIMPLIFIES">= <var>fractionReduce( SLN_NUMERATOR, SLN_DENOMINATOR )</var></span>
  113
+						</code>
  114
+					</p>
  115
+				</div> <!-- hints -->
  116
+			</div> <!-- polynomial -->
  117
+		</div> <!-- problems -->
  118
+	</div> <!-- exercise -->
  119
+</body>
  120
+</html>
5  utils/answer-types.js
@@ -101,7 +101,10 @@ jQuery.extend( Khan.answerTypes, {
101 101
 				.replace( /\u2212/, "-" )
102 102
 
103 103
 				// Remove space after +, -
104  
-				.replace( /([+-])\s+/g, "$1" );
  104
+				.replace( /([+-])\s+/g, "$1" )
  105
+
  106
+				// Remove leading/trailing whitespace
  107
+				.replace(/(^\s*)|(\s*$)/gi,"");
105 108
 
106 109
 				// Extract numerator and denominator
107 110
 			var match = text.match( /^([+-]?\d+)\s*\/\s*([+-]?\d+)$/ );

0 notes on commit 346c6d9

Please sign in to comment.
Something went wrong with that request. Please try again.