Difference between revisions of "DomainRange1"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 16: Line 16:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 40%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 43: Line 43:
   
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
'PGstandard.pl',
"MathObjects.pl",
+
'MathObjects.pl',
"contextInequalities.pl",
+
'contextInequalities.pl',
"AnswerFormatHelp.pl",
+
'PGML.pl',
  +
'PGcourse.pl'
 
);
 
);
   
Line 66: Line 66:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric");
 
  +
$f = Compute('sqrt(x-4)');
   
$f = Compute("sqrt(x-4)");
 
  +
Context('Inequalities-Only')->variables->are(x=>'Real');
 
Context("Inequalities-Only")->variables->are(x=>"Real");
 
 
Context()->flags->set(formatStudentAnswer=>'parsed');
 
Context()->flags->set(formatStudentAnswer=>'parsed');
   
$domain = Compute("x >= 4");
+
$domain = Compute('x >= 4');
  +
  +
# the context needs to change for the range
  +
Context('Inequalities-Only')->variables->are(y=>'Real');
  +
Context()->flags->set(formatStudentAnswer=>'parsed');
  +
$range = Compute('y >= 0');
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
<b>Setup 1:</b>
+
<b>Setup:</b>
 
We specify the context in a way that requires students to enter their answer using inequalities and the variable x. If we had used <code>Context("Inequalities")</code> instead, then students would also be able to enter answers using interval notation. For more details, please see [http://webwork.maa.org/pod/pg/macros/contextInequalities.html contextInequalities.pl]
 
We specify the context in a way that requires students to enter their answer using inequalities and the variable x. If we had used <code>Context("Inequalities")</code> instead, then students would also be able to enter answers using interval notation. For more details, please see [http://webwork.maa.org/pod/pg/macros/contextInequalities.html contextInequalities.pl]
 
</p>
 
</p>
Line 84: Line 82:
 
We use <code>formatStudentAnswer=>'parsed'</code> and <code>Compute()</code> so that the student's answer are left as fractions rather than reduced to decimals.
 
We use <code>formatStudentAnswer=>'parsed'</code> and <code>Compute()</code> so that the student's answer are left as fractions rather than reduced to decimals.
 
</p>
 
</p>
  +
<p>For the domain, since the variable is now <tt>y</tt>, we must reset the context and the variable so that students must enter the variable y in their answer.</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 92: Line 91:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
Suppose [` f(x) = [$f] `]. Enter inequalities for the
Suppose \( f(x) = $f \). Enter inequalities for the
 
  +
domain and range of [` f `].
domain and range of \( f \).
 
$BR
 
$BR
 
Domain:
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("inequalities") \}
 
$BR
 
END_TEXT
 
Context()->normalStrings;
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<b>Main Text 1:</b>
 
</p>
 
</td>
 
</tr>
 
   
<!-- Answer evaluation section -->
 
  +
- Domain: [_______]{$domain}
   
<tr valign="top">
 
  +
- Range: [_________________]{$range}
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers = 1;
 
   
ANS( $domain->cmp() );
 
  +
[@ helpLink('inequalities') @]*
</pre>
 
  +
END_PGML
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Answer Evaluation 1:</b>
 
</p>
 
</td>
 
</tr>
 
 
 
 
<!-- Setup section -->
 
 
<tr valign="top">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
Context("Inequalities-Only")->variables->are(y=>"Real");
 
Context()->flags->set(formatStudentAnswer=>'parsed');
 
 
$range = Compute("y >= 0");
 
</pre>
 
</td>
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<b>Setup 2:</b>
 
We must reset the context and the variable so that students must enter the variable y in their answer.
 
</p>
 
</td>
 
</tr>
 
 
<!-- Main text section -->
 
 
<tr valign="top">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
Context()->texStrings;
 
BEGIN_TEXT
 
Range:$SPACE$SPACE
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("inequalities") \}
 
END_TEXT
 
Context()->normalStrings;
 
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Main Text 2:</b>
+
<b>Main Text:</b>
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
 
<!-- Answer evaluation section -->
 
 
<tr valign="top">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
ANS( $range ->cmp() );
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Answer Evaluation 2:</b>
 
</p>
 
</td>
 
</tr>
 
 
   
   
Line 190: Line 115:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
${PAR}SOLUTION:${PAR}
 
 
Solution explanation goes here.
 
Solution explanation goes here.
END_SOLUTION
 
  +
END_PGML_SOLUTION
Context()->normalStrings;
 
 
COMMENT('MathObject version.');
 
 
ENDDOCUMENT();
 
 
</pre>
 
</pre>
 
<td style="background-color:#ddddff;padding:7px;">
 
<td style="background-color:#ddddff;padding:7px;">

Revision as of 12:56, 10 March 2023

Domain and Range of a Function

Click to enlarge

This PG code shows how to evaluate answers that are inequalities which use different variables.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
  'PGstandard.pl',
  'MathObjects.pl',
  'contextInequalities.pl',
  'PGML.pl',
  'PGcourse.pl'
);

TEXT(beginproblem());

Initialization: We must load contextInequalities.pl.

$f = Compute('sqrt(x-4)');

Context('Inequalities-Only')->variables->are(x=>'Real');
Context()->flags->set(formatStudentAnswer=>'parsed');

$domain = Compute('x >= 4');

# the context needs to change for the range
Context('Inequalities-Only')->variables->are(y=>'Real');
Context()->flags->set(formatStudentAnswer=>'parsed');
$range  = Compute('y >= 0');

Setup: We specify the context in a way that requires students to enter their answer using inequalities and the variable x. If we had used Context("Inequalities") instead, then students would also be able to enter answers using interval notation. For more details, please see contextInequalities.pl

We use formatStudentAnswer=>'parsed' and Compute() so that the student's answer are left as fractions rather than reduced to decimals.

For the domain, since the variable is now y, we must reset the context and the variable so that students must enter the variable y in their answer.

BEGIN_PGML
Suppose [` f(x) = [$f] `].  Enter inequalities for the
domain and range of [` f `].

- Domain: [_______]{$domain}

- Range: [_________________]{$range}

[@ helpLink('inequalities') @]*
END_PGML

Main Text:

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

Solution:

Templates by Subject Area