Permalink
Browse files

Trig identity exercise

  • Loading branch information...
1 parent fb9c771 commit acc0089467ec46909c90f8a2214e470704b26cde @igorT igorT committed Jul 22, 2011
Showing with 276 additions and 0 deletions.
  1. +57 −0 exercises/trig_identities_1.html
  2. +219 −0 utils/convert-values.js
View
57 exercises/trig_identities_1.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html data-require="math math-format convert-values">
+<head>
+ <title>Trigonometry identities 1</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="vars">
+ <var id="START_TYPE">trigTypes[randRange(0,trigTypes.length-1)]</var>
+
+ <var id="END_TYPE" data-ensure="START_TYPE !== END_TYPE && !((START_TYPE.name === 'sin' || START_TYPE.name === 'cos') && END_TYPE.name === 'tan' ) ">trigTypes[randRange(0,trigTypes.length-1)]</var>
+ <var id="END_NAME">END_TYPE.name</var>
+ <var id="FUN_NAME">START_TYPE.name</var>
+ <var id="ANGLE">function(){
+ if ( START_TYPE.name === "tan" ){
+ return randFromArray([0,30,45,60]);
+ }
+ else if ( START_TYPE.name === "sec" ){
+ return randFromArray([0,30,45,60]);
+ }
+ else if (START_TYPE.name === "csc" ){
+ return randFromArray([30,45,60,90]);
+ }
+ else{
+ return randFromArray([0,30,45,60,90]);
+ }}()
+
+ </var>
+ <var id="FUN_VALUE">START_TYPE.print( ANGLE )</var>
+ <var id="SOLUTION">END_TYPE.print( ANGLE )</var>
+ <var id="STEPS">findSteps(START_TYPE , END_TYPE, ANGLE)</var>
+
+ <var id="WRONG_ANGLE1" data-ensure="ANGLE !== WRONG_ANGLE1"> randFromArray([0,30,45,60,90])</var>
+ <var id="WRONG_ANGLE2" data-ensure="ANGLE !== WRONG_ANGLE2 && WRONG_ANGLE2 !== WRONG_ANGLE1"> randFromArray([0,30,45,60,90])</var>
+ <var id="NUM_ANSWERS">["","","","","","","","","","","",""]</var>
+
+ </div>
+
+ <div class="problems">
+ <div>
+ <p class="question">Given that x is in first quadrant and <code> \<var>FUN_NAME</var> x </code> is <code><var>FUN_VALUE</var></code> what is <code> \<var>END_NAME</var> x</code> ?</p>
+
+
+ <p class="solution"><code><var>SOLUTION</var></code></p>
+ <ul class="choices" data-show="4" data-none="true">
+ <li data-each="NUM_ANSWERS"><code><var>trigTypes[randRange(0,trigTypes.length-1)].print( randFromArray([0,30,45,60,90]) )</var></code></li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="hints">
+ <div data-each="STEPS as step"><p data-each="step as value"><code><var>value</var></code></p><hr></div>
+ </div>
+ </div>
+</body>
+</html>
View
219 utils/convert-values.js
@@ -0,0 +1,219 @@
+jQuery.extend( KhanUtil, {
+ trigFunc: {
+ csc: {name: "csc", print: function( angle ){
+ return KhanUtil.trigFunc.sec.print( 90-angle);
+ },
+ convertsTo:["sin"],
+ convertTo: function( type, angle ){
+ if( type.name == "sin" ){
+ var cscv = KhanUtil.trigFunc.csc.print( angle );
+ var sinv = KhanUtil.trigFunc.sin.print( angle );
+ toReturn = new Array();
+ toReturn.push( "\\csc x = \\frac{1}{\\sin x}" );
+ toReturn.push( "\\csc x = " + cscv );
+ toReturn.push( '\\frac{1}{\\sin x} = ' + cscv );
+ toReturn.push( '\\sin x = ' + sinv );
+ return toReturn;
+ }
+
+ }
+ },
+ sec: {name: "sec", print: function( angle ){
+ if( angle == 0 ){
+ return 1;
+ }
+ else if( angle == 30 ){
+ return "\\frac{2}{\\sqrt 3}";
+ }
+ else if( angle == 45 ){
+ return '\\sqrt 2';
+ }
+ else if( angle == 60 ){
+ return '2';
+ }
+ else if( angle == 90 ){
+ return 'undefined';
+ }
+ return 'undef';
+ },
+ convertsTo: ["cos","tan"],
+ convertTo: function( type, angle){
+ if( type.name == "cos" ){
+ var cosv = KhanUtil.trigFunc.cos.print( angle );
+ var secv = KhanUtil.trigFunc.sec.print( angle );
+ toReturn = new Array();
+ toReturn.push( "\\sec x = \\frac{1}{\\cos x}" );
+ toReturn.push( "\\sec x = " + secv );
+ toReturn.push( '\\frac{1}{\\cos x} = ' + secv );
+ toReturn.push( "\\cos x = " + cosv);
+ return toReturn;
+ }
+ else if( type.name == "tan"){
+ var tanv = KhanUtil.trigFunc.tan.print( angle );
+ var secv = KhanUtil.trigFunc.sec.print( angle );
+ toReturn = new Array();
+ toReturn.push( "\\sin^2 x + \\cos^2 x = 1" );
+ toReturn.push( "\\frac{\\sin^2 x}{\\cos^2 x} + \\frac{\\cos^2 x}{\\cos^2 x} = \\frac{1}{\\cos^2 x}" );
+ toReturn.push( "\\tan^2 x + 1 = \\sec^2 x" );
+ toReturn.push( "\\tan^2 x + 1 = (" + secv + ")^2" );
+ toReturn.push( "\\tan^2 x = (" + secv + ")^2 - 1" );
+ toReturn.push( "\\tan x = \\sqrt { " + secv + " ^2 - 1 }");
+ toReturn.push( "\\tan x = " + tanv );
+ return toReturn;
+ }
+ }
+ },
+ tan: {name: "tan", print: function( angle ){
+ if( angle == 0 ){
+ return 0;
+ }
+ else if( angle == 30 ){
+ return "\\frac{1}{\\sqrt 3}";
+ }
+ else if( angle == 45 ){
+ return '1';
+ }
+ else if( angle == 60 ){
+ return '\\sqrt 3';
+ }
+ else if( angle == 90 ){
+ return 'undefined';
+ }
+ return 'undef';
+
+ },
+ convertsTo: ["sec"],
+ convertTo: function( type, angle){
+ if( type.name == "sec" ){
+
+ var tanv = KhanUtil.trigFunc.tan.print( angle );
+ var secv = KhanUtil.trigFunc.sec.print( angle );
+ toReturn = new Array();
+ toReturn.push( "\\sin^2 x + \\cos^2 x = 1" );
+ toReturn.push( "\\frac{\\sin^2 x}{\\cos^2 x} + \\frac{\\cos^2 x}{\\cos^2 x} = \\frac{1}{\\cos^2 x}" );
+ toReturn.push( "\\tan^2 x + 1 = \\sec^2 x" );
+ toReturn.push( "(" + tanv + ")^2 + 1 = \\sec^2 x" );
+ toReturn.push( "\\sqrt{(" + tanv + ")^2 + 1} = \\sec x" );
+ toReturn.push( secv + ' = \\sec x');
+ return toReturn;
+ }
+ }
+ },
+ cos :{name: "cos", print: function( angle ){
+ return KhanUtil.trigFunc.sin.print( 90-angle );
+ },
+ convertsTo: ["sin","sec"],
+ convertTo: function( type, angle){
+ if( type.name == "sin" ){
+ var cosv = KhanUtil.trigFunc.cos.print( angle );
+ var sinv = KhanUtil.trigFunc.sin.print( angle );
+ toReturn = new Array();
+ toReturn.push("\\sin^2 x + \\cos^2 x = 1");
+ toReturn.push("\\sin^2 x + (" + cosv + ")^2 = 1");
+ toReturn.push("(" + cosv + ")^2 = 1 - \\sin^2 x");
+ toReturn.push('(' + cosv + ')^2 - 1 = - \\sin^2 x');
+ toReturn.push('-(' + cosv + ')^2 + 1 = \\sin^2 x');
+ toReturn.push(sinv + ' = \\sin x');
+ return toReturn;
+ }
+ else if( type.name == "sec" ){
+ cosv = KhanUtil.trigFunc.cos.print( angle );
+ secv = KhanUtil.trigFunc.sec.print( angle );
+ toReturn = new Array();
+ toReturn.push( cosv + " = \\cos x" );
+ toReturn.push( secv + " = \\frac{1}{\\cos x}" );
+ toReturn.push( secv + " = \\sec x" );
+ return toReturn;
+ }
+ }
+ },
+ sin: {name: "sin", print: function( angle ){
+ if( angle == 0 ){
+ return 0;
+ }
+ else if( angle == 30 ){
+ return '\\frac{1}{2}';
+ }
+ else if( angle == 45 ){
+ return '\\frac{\\sqrt 2}{2}';
+ }
+ else if( angle == 60 ){
+ return '\\frac{\\sqrt 3}{2}';
+ }
+ else if( angle == 90 ){
+ return '1';
+ }
+ return 'undefined';
+ },
+ convertsTo: ["cos","csc"],
+ convertTo: function( type, angle ){
+ if( type.name == "cos" ){
+ var sinv = KhanUtil.trigFunc.sin.print( angle );
+ var cosv = KhanUtil.trigFunc.cos.print( angle );
+ toReturn = new Array();
+ toReturn.push( "\\sin^2 x + \\cos^2 x = 1" );
+ toReturn.push( "(" + sinv + ")^2 + \\cos^2 x = 1" );
+ toReturn.push( "(" + sinv + ")^2 = 1- \\cos^2 x " );
+ toReturn.push( "(" + sinv + ")^2 - 1 = - \\cos^2 x " );
+ toReturn.push( "-(" + sinv + ")^2 + 1 = \\cos^2 x " );
+ toReturn.push( cosv + " = \\cos x" );
+ return toReturn;
+
+ }
+ else if( type.name == "csc" ){
+ var sinv = KhanUtil.trigFunc.sin.print( angle )
+ var cscv = KhanUtil.trigFunc.csc.print( angle );
+
+ toReturn = new Array();
+ toReturn.push( sinv + " = \\sin x" );
+ toReturn.push( cscv + " = \\frac{1}{\\sin x}" );
+ toReturn.push( cscv + " = \\csc x" );
+ return toReturn;
+ }
+ }
+
+ }
+}})
+
+jQuery.extend( KhanUtil, {
+ trigTypes: [KhanUtil.trigFunc.sin,KhanUtil.trigFunc.cos,KhanUtil.trigFunc.tan,KhanUtil.trigFunc.csc,KhanUtil.trigFunc.sec],
+
+ findSteps: function( start, end, value){
+ var visited = {};
+ var queue=[];
+ var next=start;
+ while( next.name != end.name ){
+ if ( next.convertsTo ) {
+ $.each( next.convertsTo, function(i, str) {
+ if( ! (str in visited) ){
+ var move = KhanUtil.trigFunc[str];
+ move["parent"] = next;
+ queue.push( move );
+ }
+ visited[str] = true;
+ });
+ }
+ next = queue.shift();
+ }
+ var prev = next;
+ var steps = new Array();
+ while( prev.name != start.name ){
+ steps.unshift( prev.name );
+ prev = prev.parent;
+
+ }
+ steps.unshift( prev.name );
+ var toReturn = new Array();
+ for( x=0; x<steps.length-1 ;x++ ){
+ // Vars cannot have circular references, so delete .parent before returning
+ var step = KhanUtil.trigFunc[steps[x]].convertTo( KhanUtil.trigFunc[steps[x+1]], value );
+ delete step.parent;
+
+ toReturn.push( step );
+ }
+ for( x=0; x<KhanUtil.trigTypes.length-1 ;x++ ){
+ delete KhanUtil.trigTypes[x].parent;
+ }
+ return toReturn;
+ }
+})

0 comments on commit acc0089

Please sign in to comment.