Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

91 lines (88 sloc) 3.8 kB
<!DOCTYPE html>
<html data-require="math math-format">
<head>
<meta charset="UTF-8" />
<title>Adding and subtracting complex numbers</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="A_REAL">randRange( -5, 5 )</var>
<var id="A_IMAG">randRange( -5, 5 )</var>
<var id="B_REAL">randRange( -5, 5 )</var>
<var id="B_IMAG">randRange( -5, 5 )</var>
<var id="OPERATION">randFromArray( [ "add", "subtract" ] )</var>
<var id="OPERATOR">( OPERATION === "add" ? "+" : "-" )</var>
<var id="ANSWER_REAL">
( OPERATION === "add" ? ( A_REAL + B_REAL ) : ( A_REAL - B_REAL ) )
</var>
<var id="ANSWER_IMAG">
( OPERATION === "add" ? ( A_IMAG + B_IMAG ) : ( A_IMAG - B_IMAG ) )
</var>
<var id="A_REP">
complexNumber(A_REAL, A_IMAG)
</var>
<var id="B_REP">
complexNumber(B_REAL, B_IMAG)
</var>
<var id="A_REP_COLORED">
"\\color{" + ORANGE + "}{" + A_REP + "}"
</var>
<var id="B_REP_COLORED">
"\\color{" + BLUE + "}{" + B_REP + "}"
</var>
<var id="A_REAL_COLORED">
"\\color{" + ORANGE + "}{" + A_REAL + "}"
</var>
<var id="A_IMAG_COLORED">
"\\color{" + ORANGE + "}{" + A_IMAG + "}"
</var>
<var id="B_REAL_COLORED">
"\\color{" + BLUE + "}{" + B_REAL + "}"
</var>
<var id="B_IMAG_COLORED">
"\\color{" + BLUE + "}{" + B_IMAG + "}"
</var>
</div>
<div class="problems">
<div>
<p class="question"><var>OPERATION == "add" ? "Add" : "Subtract"</var> the following complex numbers:</p>
<p>
<code>
(<var>A_REP_COLORED</var>) <var>OPERATOR</var> (<var>B_REP_COLORED</var>)
</code>
</p>
<div class="solution" data-type="complexNumberSeparate">
[ <var>ANSWER_REAL</var>, <var>ANSWER_IMAG</var> ]
</div>
<div class="hints">
<p>
Complex numbers can be <var>OPERATION</var>ed by separately <var>OPERATION</var>ing their real and imaginary components.
</p>
<p>
The real components of the two complex numbers are <code class="hint_orange"><var>A_REAL</var></code> and <code class="hint_blue"><var>B_REAL</var></code>, respectively,
so the real component of the result will be
<code>
<var>A_REAL_COLORED</var> <var>OPERATOR</var> \color{<var>BLUE</var>}{<var>negParens(B_REAL)</var>}
</code>,
which equals <code><var>ANSWER_REAL</var></code>.
</p>
<p>
The imaginary components of the two complex numbers are <code class="hint_orange"><var>A_IMAG</var></code> and <code class="hint_blue"><var>B_IMAG</var></code>, respectively,
so the imaginary component of the result will be
<code>
<var>A_IMAG_COLORED</var> <var>OPERATOR</var> \color{<var>BLUE</var>}{<var>negParens(B_IMAG)</var>}
</code>,
which equals <code><var>ANSWER_IMAG</var></code>.
</p>
<p>
The result is <code><var>complexNumber(ANSWER_REAL, ANSWER_IMAG)</var></code>; its real component is <code><var>ANSWER_REAL</var></code>
and its complex component is <code><var>ANSWER_IMAG</var></code>.
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.