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

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '== Flash Applets embedded in WeBWorK questions u-subsitution Example == <h2>Sample Problem with uSub.swf embedded</h2> <p style="background-color:#eeeeee;border:black solid 1px;…')
 
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Flash Applets embedded in WeBWorK questions u-subsitution Example ==
+
== Flash Applets embedded in hint portion of WeBWorK questions Example ==
   
<h2>Sample Problem with uSub.swf embedded</h2>
+
<h2>Sample Problem with trigSubWW.swf embedded</h2>
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em>This sample problem shows how to use the u-substitution applet.</em>
+
<em>This sample problem shows how to use embed an applet in the hint portion of a WeBWorK problem.</em>
 
</p>
 
</p>
  +
<p style="background-color:#93BED2;border:black solid 1px;padding:3px;">This applet and WeBWorK problem are based upon work supported by the National Science Foundation under Grant Number DUE-0941388.</p>
 
<p>
 
<p>
 
A standard WeBWorK PG file with an embedded applet has six sections:
 
A standard WeBWorK PG file with an embedded applet has six sections:
Line 17: Line 18:
 
</ol>
 
</ol>
 
<p>
 
<p>
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.
+
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.
  +
<br>
  +
[[File:trigSub.jpg]]
  +
<br>
  +
<oflash>file="images/0/0d/TrigSubWWpic.swf"|height=400px|width=550px</oflash>
  +
<br>
 
<br>
 
<br>
 
Other applet sample problems: <br>
 
Other applet sample problems: <br>
 
[[GraphLimit Flash Applet Sample Problem]]<br>[[GraphLimit Flash Applet Sample Problem 2]]<br>[[Derivative Graph Matching Flash Applet Sample Problem]]<br>
 
[[GraphLimit Flash Applet Sample Problem]]<br>[[GraphLimit Flash Applet Sample Problem 2]]<br>[[Derivative Graph Matching Flash Applet Sample Problem]]<br>
[[Hint Applet (Trigonometric Substitution) Sample Problem]]
 
 
</p>
 
</p>
   
Line 30: Line 30:
 
| <pre>
 
| <pre>
 
##DESCRIPTION
 
##DESCRIPTION
## Integration with substitution
+
##KEYWORDS('integrals', 'trigonometric','substitution')
##ENDDESCRIPTION
 
 
##KEYWORDS('integral', 'substitution')
 
   
 
## DBsubject('Calculus')
 
## DBsubject('Calculus')
## DBchapter('Integration')
+
## DBchapter('Techniques of Integration')
## DBsection('Integration with substitution')
+
## DBsection('Trigonometric Substitution')
## Date('6/9/2011')
+
## Date('8/20/11')
 
## Author('Barbara Margolius')
 
## Author('Barbara Margolius')
 
## Institution('Cleveland State University')
 
## Institution('Cleveland State University')
 
## TitleText1('')
 
## TitleText1('')
## EditionText1('2011')
+
## EditionText1('2010')
 
## AuthorText1('')
 
## AuthorText1('')
 
## Section1('')
 
## Section1('')
## Problem1('')
+
## Problem1('20')
  +
##ENDDESCRIPTION
 
########################################
 
########################################
 
# This work is supported in part by the
 
# This work is supported in part by the
Line 65: Line 65:
   
 
loadMacros(
 
loadMacros(
"PGbasicmacros.pl",
+
"PGstandard.pl",
"extraAnswerEvaluators.pl",
 
 
"AppletObjects.pl",
 
"AppletObjects.pl",
  +
"MathObjects.pl",
  +
"parserFormulaUpToConstant.pl",
 
);
 
);
 
</pre>
 
</pre>
Line 80: Line 82:
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
Context("Numeric");
 
Context()->variables->add(u=>"Real");
 
   
$b = random(1,2,1);
+
$a = random(2,9,1);
$ubig = Compute("$b+$b^2")+random(1,2,1);
 
$vbig = Compute("2+2*($b+$b^2)");
 
$vsmall = -$vbig;
 
   
$anslist = List(
 
  +
$a2 = $a*$a;
Compute("cos(u)"),
 
  +
$a3 = $a2*$a;
Compute("0"),
 
  +
$a4 = $a2*$a2;
Compute("$b+$b^2"),
 
  +
$a4_3 = 3*$a4;
Compute("sin($b+$b^2)"));
 
  +
$a2_5 = 5*$a2;
  +
  +
$funct = FormulaUpToConstant("-sqrt{$a2-x^2}/{x}-asin({x}/{$a})");
   
 
</pre>
 
</pre>
Line 96: Line 98:
 
</p>
 
</p>
 
<p>
 
<p>
The uSub.swf applet has the student enter a four part solution: the integrand after the u-substitution, the lower limit of integration in terms of u, the upper limit of integration in terms of u, and the value of the integral. The correct answer must be entered in list format in the pg file. That is what the code <code>$anslist = List(Compute("cos(u)"),</code> <code>Compute("0"),</code><code>Compute("$b+$b^2"),</code> <code>Compute("sin($b+$b^2)"));</code> does. The line <code>Context()->variables->add(u=>"Real");</code> adds the variable u to the context. <code>$vbig</code> and <code>$vsmall</code> are the vertical axes graph window settings. These can be different for the two graphs, but this is generally not a good idea as the purpose of the applet is to show the student that after a u-substitution, the are of the integrand will be the same even though the shape of the graph may change. Functions must be carefully chosen to convey this message and so that the two graph windows can be the same size. <code>$ubig</code> is the maximum value of the horizontal graph window for both graphs. The minimum value for this problem is coded in the pg file to '-3'. This is not necessary, it can be set to any value smaller than the maximum horizontal window value.
 
  +
The <code>FormulaUpToConstant("-sqrt{$a2-x^2}/{x}-asin({x}/{$a})");</code> 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.
 
</p>
 
</p>
 
|- style="background-color:#ccffff;"
 
|- style="background-color:#ccffff;"
Line 103: Line 105:
 
# Create link to applet
 
# Create link to applet
 
###################################
 
###################################
$appletName = "uSub";
+
$appletName = "trigSubWW";
 
$applet = FlashApplet(
 
$applet = FlashApplet(
codebase
+
codebase =>
=> findAppletCodebase("$appletName.swf"),
+
findAppletCodebase("$appletName.swf"),
appletName => $appletName,
+
appletName => $appletName,
appletId => $appletName,
+
appletId => $appletName,
setStateAlias => 'setXML',
+
setStateAlias => 'setXML',
getStateAlias => 'getXML',
+
getStateAlias => 'getXML',
setConfigAlias => 'setConfig',
+
setConfigAlias => 'setConfig',
maxInitializationAttempts => 5,
+
maxInitializationAttempts => 10,
answerBoxAlias => 'answerBox',
+
height => '550',
height => '550',
+
width => '595',
width => '700',
+
bgcolor => '#e8e8e8',
bgcolor => '#e8e8e8',
+
debugMode => 0,
debugMode => 0,
+
onInit => 'ggbOnInit',
submitActionScript =>
+
);
qq{getQE("answerBox").value
 
=getApplet("$appletName").getAnswer() },
 
);
 
 
###################################
 
###################################
 
# Configure applet
 
# Configure applet
 
###################################
 
###################################
 
 
#initially the answers will be blank
 
  +
$applet->configuration(qq
$applet->configuration(qq{<xml>
 
  +
{<xml><trigString>sin</trigString></xml>});
<plot func='(1+2*x)*cos(x+x^2)'
 
  +
$applet->initialState(qq
lower='0' upper='$b'/>
 
  +
{<xml><trigString>sin</trigString></xml>});
<grids xgrid='1' ygrid='$b'/>
 
<win xmin='-3' xmax='$ubig'
 
ymin='$vsmall' ymax='$vbig'
 
umin='-3' umax='$ubig'
 
vmin='$vsmall' vmax='$vbig' />
 
<ans func='' lower='' upper =''
 
theValue='' />
 
<usub ufunc='x+x^2'/></xml>});
 
#initially the answers will be blank
 
$applet->initialState(qq{<xml>
 
<plot func='(1+2*x)*cos(x+x^2)'
 
lower='0' upper='$b'/>
 
<grids xgrid='1' ygrid='$b'/>
 
<win xmin='-3' xmax='$ubig'
 
ymin='$vsmall' ymax='$vbig'
 
umin='-3' umax='$ubig'
 
vmin='$vsmall' vmax='$vbig' />
 
<ans func='' lower='' upper =''
 
theValue='' />
 
<usub ufunc='x+x^2'/></xml>});
 
   
TEXT( MODES(TeX=>'object code',
+
TEXT(MODES(TeX=>"", HTML=><<'END_TEXT'));
HTML=>$applet->insertAll(
+
<script>
debug=>0,
+
if (navigator.appVersion.indexOf("MSIE") > 0) {
includeAnswerBox=>1,
+
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
  +
##################################
  +
# Setup Flash applet
  +
# -- this does not need to be changed
  +
###################################
  +
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>
Line 160: Line 142:
 
Those portions of the code that begin the line with <code>#</code> are comments and can be omitted or replaced with comments appropriate to your particular problem.
 
Those portions of the code that begin the line with <code>#</code> are comments and can be omitted or replaced with comments appropriate to your particular problem.
 
</p>
 
</p>
<p>You must include the section that follows <code># Create link to applet</code>. If you are embedding a different applet, from the uSub applet, put your applet name in place of 'uSub' in the line <code>$appletName = "uSub";</code>. Enter the height of the applet in the line <code>height => '550',</code> in place of 550 and the width in the line <code>width => '700',</code> in place of 700.
+
<p>You must include the section that follows <code># Create link to applet</code>. If you are embedding a different applet, from the trigSubWW applet, put your applet name in place of 'trigSubWW' in the line <code>$appletName = "trigSubWW";</code>. Enter the height of the applet in the line <code>height => '550',</code> in place of 550 and the width in the line <code>width => '595',</code> in place of 595.
 
</p><br>
 
</p><br>
<p> The lines <code>$applet-></code> <code>configuration(qq{<xml><plot func='(1+2*x)*cos(x+x^2)' </code> <code>lower='0' upper='$b'/></code> <code><br>
+
<p> The lines <code>$applet-></code> <code>configuration(qq{</code> <code><xml><trigString>sin</trigString></xml>});</code> and <code>$applet-></code> <code>initialState(qq{</code> <code><xml><trigString>sin</trigString></xml>});</code>
<grids xgrid='1' ygrid='$b'/></code> <code><br>
+
<br> configure the applet. There are three possible settings: "tan", "sin" and "sec" for each of the basic trigonometric substitutions.
<win xmin='-3' xmax='$ubig' ymin='$vsmall' ymax='$vbig'
 
umin='-3' umax='$ubig' vmin='$vsmall' vmax='$vbig' /></code> <code><br>
 
<ans func='' lower='' upper ='' theValue='' /></code> <code><br>
 
<usub ufunc='x+x^2'/></xml>});</code>
 
<br>
 
and
 
<br>
 
<code>$applet-></code> <code>initialState(qq{<xml><plot func='(1+2*x)*cos(x+x^2)' </code> <code>lower='0' upper='$b'/></code> <code><br>
 
<grids xgrid='1' ygrid='$b'/></code> <code><br>
 
<win xmin='-3' xmax='$ubig' ymin='$vsmall' ymax='$vbig'
 
umin='-3' umax='$ubig' vmin='$vsmall' vmax='$vbig' /></code> <code><br>
 
<ans func='' lower='' upper ='' theValue='' /></code> <code><br>
 
<usub ufunc='x+x^2'/></xml>});</code>
 
<br> configure the applet. The configuration of the applet is done in xml. The applet expects to be told the integrand of the original integral (func='(1+2*x)*cos(x+x^2)'), the lower limit of integration (lower='0'), the upper limit (upper='$b'), the horizontal and vertical grid spacing (xgrid='1' ygrid='$b'), the dimensions of the two graph windows (,code><win xmin='-3' xmax='$ubig' ymin='$vsmall' ymax='$vbig'
 
umin='-3' umax='$ubig' vmin='$vsmall' vmax='$vbig' /></code>) and the u-substitution the student is to use (<code><usub ufunc='x+x^2'/></code>).
 
 
</p><br>
 
</p><br>
<p>The code <code>qq{getQE("answerBox").value=getApplet("$appletName").getAnswer() }</code>
 
  +
<p>The javascript function <code>ggbOnInit</code> tells the web page that the applet is ready. This chunk of code is not necessary in Flash applet embedded problems in which the applet is embedded in the problem itself because the applet tells the page its ready when it appears on the page. Here the appearance of the applet is delayed until the student has attempted the problem a few (in this case 5) times. So without the call to this function, the page continues to check on the applet, but no applet is available.</p>
is called when the 'Submit Answers' button in the problem is pressed. This will call the getAnswer function which will return the contents of the four answer blanks in the applet.</p>
 
<br>
 
<p>
 
<code>TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll(
 
debug=>0,
 
includeAnswerBox=>0,
 
reinitialize_button=>$permissionLevel>=10,
 
)));</code> actually embeds the applet in the WeBWorK problem.
 
</p><br>
 
<p>When the submit button is pressed, the hidden form fields defined in this block are filled with information from the applet.
 
</p>
 
 
|- style=" background-color:#ccffff;"
 
|- style=" background-color:#ccffff;"
 
| <pre>
 
| <pre>
Line 197: Line 168:
 
BEGIN_TEXT
 
BEGIN_TEXT
   
$BR
 
  +
Evaluate the indefinite integral.
$BR Complete the indicated blanks
 
  +
$BR \[ \int\frac{\sqrt{$a2 - x^2}}{x^2}dx \]
in the applet. When done click
 
  +
$BR \{ans_rule( 60) \}
'submit answers'.
 
   
$PAR If you click 'submit answers'
 
  +
END_TEXT
before you are done, WeBWorK will
 
save your work for when you log back on.
 
   
END_TEXT
 
  +
##################################
Context()->normalStrings;
+
Context()->texStrings;
 
</pre>
 
</pre>
 
| <p>
 
| <p>
 
This is the <strong>text section</strong> of the problem. The <code>TEXT(beginproblem());</code> line displays a header for the problem, and the <code>Context()-&gt;texStrings</code> line sets how formulas are displayed in the text, and we reset this after the text section. Everything between the <code>BEGIN_TEXT</code> and <code>END_TEXT</code> lines (each of which must appear alone on a line) is shown to the student.
 
This is the <strong>text section</strong> of the problem. The <code>TEXT(beginproblem());</code> line displays a header for the problem, and the <code>Context()-&gt;texStrings</code> line sets how formulas are displayed in the text, and we reset this after the text section. Everything between the <code>BEGIN_TEXT</code> and <code>END_TEXT</code> lines (each of which must appear alone on a line) is shown to the student.
</p>
 
<p>
 
Answers are submitted within the applet, so no answer blanks are provided here. The parser in the applet is not as sophisticated as the WeBWorK parser so '*' must explicitly be entered for times in order for the function to graph within the applet. The answers are graded by WeBWorK so a correctly formulated WeBWorK answer will be marked as correct, but may not be graphable.
 
 
</p>
 
</p>
 
|- style="background-color:#eeddff;"
 
|- style="background-color:#eeddff;"
Line 223: Line 188:
 
## answer evaluators
 
## answer evaluators
   
NAMED_ANS( 'answerBox'=>$anslist->
 
  +
ANS( $funct->cmp() );
cmp(ordered=>1) );
 
   
ENDDOCUMENT();
 
  +
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();
 
</pre>
 
</pre>
 
| <p>
 
| <p>
This is the <strong>answer</strong> section of the problem. The problem answer is recorded in the applet. The code <code>NAMED_ANS( 'answerBox'=>$anslist->cmp(ordered=>1) );</code> compares the answer entered into the applet (the contents of 'answerBox') with the WeBWorK variable <code>$anslist</code>. The answer is graded as an ordered list.
+
This is the <strong>answer, hint and solution</strong> section of the problem. The code block with <code>$applet->insertAll</code> inserts the applet in the hint. The hint is displayed after the student makes 5 attempts set by <code>$showHint=5;</code>. The problem answer is recorded in the applet. The code between <code>SOLUTION(EV3(<<'END_SOLUTION'));</code> and <code>END_SOLUTION</code> provides the solution to the problem.
 
</p>
 
</p>
 
<p>
 
<p>
Line 235: Line 253:
 
</p>
 
</p>
 
|}
 
|}
  +
  +
== License ==
  +
  +
The Flash applets developed under DUE-0941388 are protected under the following license:
  +
[http://creativecommons.org/licenses/by-nc/3.0/ Creative Commons Attribution-NonCommercial 3.0 Unported License].
  +
  +
[[Category:Sample Problems]]
  +
[[Category:Applets]]
  +
[[Category:Flash Applets]]
  +
[[Category:Problem_Techniques]]

Latest revision as of 12:30, 12 June 2013

Flash Applets embedded in hint portion of WeBWorK questions Example[edit]

Sample Problem with trigSubWW.swf embedded

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

This applet and WeBWorK problem are based upon work supported by the National Science Foundation under Grant Number DUE-0941388.

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
<oflash>file="images/0/0d/TrigSubWWpic.swf"|height=400px|width=550px</oflash>

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
##################################
# Setup Flash applet 
#   -- this does not need to be changed
###################################
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.


The javascript function ggbOnInit tells the web page that the applet is ready. This chunk of code is not necessary in Flash applet embedded problems in which the applet is embedded in the problem itself because the applet tells the page its ready when it appears on the page. Here the appearance of the applet is delayed until the student has attempted the problem a few (in this case 5) times. So without the call to this function, the page continues to check on the applet, but no applet is available.

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[edit]

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