Difference between revisions of "Hint Applet (Trigonometric Substitution) Sample Problem"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 124: Line 124:
 
bgcolor => '#e8e8e8',
 
bgcolor => '#e8e8e8',
 
debugMode => 0,
 
debugMode => 0,
  +
onInit => 'ggbOnInit',
 
);
 
);
 
###################################
 
###################################
Line 145: Line 146:
 
</script>
 
</script>
 
END_TEXT
 
END_TEXT
  +
HEADER_TEXT(qq!
  +
<script language="javascript">
  +
function ggbOnInit(param) {
  +
if (param == "$appletName") {
  +
applet_loaded(param,1);
  +
// report that applet is ready.
  +
ww_applet_list[param].safe_applet_initialize(2);
  +
}
  +
}
  +
</script>
  +
!
  +
);
 
</pre>
 
</pre>
 
| <p>
 
| <p>

Revision as of 13:29, 23 August 2011

Flash Applets embedded in hint portion of WeBWorK questions Example

Sample Problem with trigSubWW.swf embedded

This sample problem shows how to use embed an applet in the hint portion of a WeBWorK problem.

A standard WeBWorK PG file with an embedded applet has six sections:

  1. A tagging and description section, that describes the problem for future users and authors,
  2. An initialization section, that loads required macros for the problem,
  3. A problem set-up section that sets variables specific to the problem,
  4. An Applet link section that inserts the applet and configures it, (this section is not present in WeBWorK problems without an embedded applet)
  5. A text section, that gives the text that is shown to the student, and
  6. An answer, hint and solution section, that specifies how the answer(s) to the problem is(are) marked for correctness, gives hints after a given number of tries and gives a solution that may be shown to the student after the problem set is complete.

The sample file attached to this page shows this; below the file is shown to the left, with a second column on its right that explains the different parts of the problem that are indicated above. Immediately is a screenshot of the WeBWorK problem with the swf file showing the step by step hints.
TrigSub.jpg
<flash>file=trigSubWWpic.swf|height=400px|width=550px</flash>

Other applet sample problems:
GraphLimit Flash Applet Sample Problem
GraphLimit Flash Applet Sample Problem 2
Derivative Graph Matching Flash Applet Sample Problem

PG problem file Explanation
##DESCRIPTION
##KEYWORDS('integrals', 'trigonometric','substitution')

## DBsubject('Calculus')
## DBchapter('Techniques of Integration')
## DBsection('Trigonometric Substitution')
## Date('8/20/11')
## Author('Barbara Margolius')
## Institution('Cleveland State University')
## TitleText1('')
## EditionText1('2010')
## AuthorText1('')
## Section1('')
## Problem1('20')
##ENDDESCRIPTION
########################################
# This work is supported in part by the 
# National Science Foundation 
# under the grant DUE-0941388.
########################################

This is the tagging and description section of the problem. Note that any line that begins with a "#" character is a comment for other authors who read the problem, and is not interpreted by WeBWorK.

The description is provided to give a quick summary of the problem so that someone reading it later knows what it does without having to read through all of the problem code.

All of the tagging information exists to allow the problem to be easily indexed. Because this is a sample problem there isn't a textbook per se, and we've used some default tagging values. There is an on-line list of current chapter and section names and a similar list of keywords. The list of keywords should be comma separated and quoted (e.g., KEYWORDS('calculus','derivatives')).

DOCUMENT();        

loadMacros(
  "PGstandard.pl",
  "AppletObjects.pl",
  "MathObjects.pl",
  "parserFormulaUpToConstant.pl",
);

This is the initialization section of the problem. The first executed line of the problem must be the DOCUMENT(); command. Note that every command must end with a semicolon.

The loadMacros command loads information that works behind the scenes. For our purposes we can usually just load the macros shown here and not worry about things further.

# Set up problem
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

$a = random(2,9,1);

$a2 = $a*$a;
$a3 = $a2*$a;
$a4 = $a2*$a2;
$a4_3 = 3*$a4;
$a2_5 = 5*$a2;

$funct = FormulaUpToConstant("-sqrt{$a2-x^2}/{x}-asin({x}/{$a})");

This is the problem set-up section of the problem.

The FormulaUpToConstant("-sqrt{$a2-x^2}/{x}-asin({x}/{$a})"); gives the antiderivative of the given integrand. The student must enter this formula or an equivalent one up to a constant. The constant must be included. Any arbitrary constant is accepted.

###################################
# Create  link to applet 
###################################
$appletName = "trigSubWW";
$applet =  FlashApplet(
   codebase              => 
    findAppletCodebase("$appletName.swf"),
   appletName            => $appletName,
   appletId              => $appletName,
   setStateAlias         => 'setXML',
   getStateAlias         => 'getXML',
   setConfigAlias        => 'setConfig',
   maxInitializationAttempts => 10,   
   height                => '550',
   width                 => '595',
   bgcolor               => '#e8e8e8',
   debugMode             =>  0,
   onInit                => 'ggbOnInit',
);
###################################
# Configure applet
###################################
 
$applet->configuration(qq
   {<xml><trigString>sin</trigString></xml>});
$applet->initialState(qq
   {<xml><trigString>sin</trigString></xml>});

TEXT(MODES(TeX=>"", HTML=><<'END_TEXT'));
<script>
if (navigator.appVersion.indexOf("MSIE") > 0) {
  document.write("<div width='3in' 
   align='center' style='background:yellow'>
   You seem to be using Internet Explorer.<br/>
   It is recommended that another browser be 
   used to view this page.</div>");
}
</script>
END_TEXT
HEADER_TEXT(qq! 
<script language="javascript">
 function ggbOnInit(param) {
  if (param == "$appletName") {
    applet_loaded(param,1);  
    // report that applet is ready. 
    ww_applet_list[param].safe_applet_initialize(2);
  }
 } 
</script>
!  
);

This is the Applet link section of the problem.


Those portions of the code that begin the line with # are comments and can be omitted or replaced with comments appropriate to your particular problem.

You must include the section that follows # Create link to applet. If you are embedding a different applet, from the trigSubWW applet, put your applet name in place of 'trigSubWW' in the line $appletName = "trigSubWW";. Enter the height of the applet in the line height => '550', in place of 550 and the width in the line width => '595', in place of 595.


The lines $applet-> configuration(qq{ <xml><trigString>sin</trigString></xml>}); and $applet-> initialState(qq{ <xml><trigString>sin</trigString></xml>});
configure the applet. There are three possible settings: "tan", "sin" and "sec" for each of the basic trigonometric substitutions.


TEXT(MODES(TeX=>"", HTML=><<'END_TEXT'));
<script>
if (navigator.appVersion.indexOf("MSIE") > 0) {
    document.write("<div width='3in' 
    align='center' style='background:yellow'>
    You seem to be using Internet Explorer.
    <br/>It is recommended that another 
    browser be used to view this page.</div>");
}
</script>
END_TEXT

The text between the <script> tags detects whether the student is using Internet Explorer. If the student is using this browser, a warning is issued and the student is advised to use another browser. IE mis-sizes the applets. Some will work correctly when displayed at the wrong size, but others will fail. We do not recommend using IE with WeBWorK problems with Flash embedded.

BEGIN_TEXT

Evaluate the indefinite integral.
$BR \[ \int\frac{\sqrt{$a2 - x^2}}{x^2}dx \]
$BR \{ans_rule( 60) \}  

END_TEXT

##################################
Context()->texStrings;

This is the text section of the problem. The TEXT(beginproblem()); line displays a header for the problem, and the Context()->texStrings line sets how formulas are displayed in the text, and we reset this after the text section. Everything between the BEGIN_TEXT and END_TEXT lines (each of which must appear alone on a line) is shown to the student.

###################################
#
#  Answers
#
## answer evaluators

ANS( $funct->cmp() );

TEXT($PAR, $BBOLD, $BITALIC, "Hi $studentLogin, 
If you don't get this in 5 tries I'll give you 
a hint with an applet to help you out.", 
$EITALIC, $EBOLD, $PAR);

$showHint=5;
Context()->normalStrings;
TEXT(hint(
 $PAR,  MODES(TeX=>'object code', HTML=>$applet->insertAll(
   debug =>0, reinitialize_button => 0, includeAnswerBox=>0,
 ))
));

##################################
Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$BBOLD Solution: $EBOLD $PAR
To evaluate this integral use a trigonometric 
substitution.  For this problem use the sine 
substitution. \[x = {$a}\sin(\theta)\]

$BR$BR
Before proceeding  note that \(\sin\theta=\frac{x}{$a}\), 
and \(\cos\theta=\frac{\sqrt{$a2-x^2}}{$a}\).  To see this, 
label a right triangle so that the sine is \(x/$a\).  We will 
have the opposite side with length \(x\), and the hypotenuse 
with length \($a\), so the adjacent side has length 
\(\sqrt{$a2-x^2}\).

$BR$BR
With the substitution \[x = {$a}\sin\theta\]
\[dx = {$a}\cos\theta \; d\theta\]
$BR$BR
Therefore:
\[\int\frac{\sqrt{$a2 - x^2}}{x^2}dx=
\int  \frac{{$a}\cos\theta\sqrt{$a2 - {$a2}\sin^2\theta}}
{{$a2}\sin^2\theta} \; d\theta\]
\[=\int  \frac{\cos^2\theta}{\sin^2\theta} \; d\theta\]
\[=\int  \cot^2\theta \; d\theta\]
\[=\int  \csc^2\theta-1 \; d\theta\]
\[=-\cot\theta-\theta+C\]

$BR$BR
Substituting back in terms of \(x\) yields:
\[-\cot\theta-\theta+C
=-\frac{\sqrt{$a2-x^2}}{x}-\sin^{-1}\left(\frac{x}{$a}\right)+C
\]

so
\[  \int\frac{\sqrt{$a2 - x^2}}{x^2}dx
=-\frac{\sqrt{$a2-x^2}}{x}-\sin^{-1}\left(\frac{x}{$a}\right)+C\]
END_SOLUTION
Context()->normalStrings;
##################################
ENDDOCUMENT();      

This is the answer, hint and solution section of the problem. The code block with $applet->insertAll inserts the applet in the hint. The hint is displayed after the student makes 5 attempts set by $showHint=5;. The problem answer is recorded in the applet. The code between SOLUTION(EV3(<<'END_SOLUTION')); and END_SOLUTION provides the solution to the problem.

The ENDDOCUMENT(); command is the last command in the file.

License

The Flash applets developed under DUE-0941388 are protected under the following license: Creative Commons Attribution-NonCommercial 3.0 Unported License.