ShiftingScalingGraphs
Shifting and Scaling Graphs or Graph Transformations
This PG code shows how to check a student answer that is a shifted and scaled version of a named function.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGgraphmacros.pl", "parserFunction.pl", "unionTables.pl", ); TEXT(beginproblem()); |
Initialization:
We need to include the macros file |
Context("Numeric"); parserFunction("f(x)" => "e^(x/pi)+sin(e*x)"); $answer = Formula("-f(-2x)+1"); foreach my $i (0..1) { $gr[$i] = init_graph(-5,-5,5,5,axes=>[0,0],grid=>[10,10],size=>[400,400]); $gr[$i]->lb('reset'); $gr[$i]->lb( new Label(4.5,0.25,'x','black','center','middle')); $gr[$i]->lb( new Label(0.25,4.5,'y','black','center','middle')); foreach my $j (1..4) { $gr[$i]->lb( new Label(-4.5, $j, $j,'black','center','middle')); $gr[$i]->lb( new Label(-4.5,-$j,-$j,'black','center','middle')); $gr[$i]->lb( new Label($j, -4.5, $j,'black','center','middle')); $gr[$i]->lb( new Label(-$j,-4.5,-$j,'black','center','middle')); } } $gr[0]->moveTo(-4, 3); $gr[0]->lineTo(-2, 3,'blue',3); $gr[0]->lineTo( 0, 0,'blue',3); $gr[0]->lineTo( 2, 1,'blue',3); $gr[1]->moveTo(-1, 0); $gr[1]->lineTo( 0, 1,'red',3); $gr[1]->lineTo( 1,-2,'red',3); $gr[1]->lineTo( 2,-2,'red',3); foreach my $i (0..1) { $fig[$i] = image(insertGraph($gr[$i]),width=>400,height=>400,tex_size=>450); } |
Setup:
First, we define a named function Second, we graph some piecewise functions for which students will be unable to enter an explicit formula. To make this example easier to follow, we did not randomize this question. |
BEGIN_TEXT The graph of a function \( y = f(x) \) is given in the figure on the left. The graph of the function \( g(x) \) on the right can be obtained from the graph of \( f \) by horizontal and vertical scaling and shifting. What is a formula for \( g(x) \) in terms of \( f(x) \)? $BR $BR \( g(x) \) = \{ ans_rule(20) \} $BR $BR \{ BeginTable(). AlignedRow([$fig[0],$fig[1]]). TableSpace(5,0). AlignedRow(["Graph of \( f(x) \)","Shifted and scaled graph \( g(x) \)"]). EndTable() \} END_TEXT |
Main Text: We use a table to display the graphs nicely. |
$showPartialCorrectAnswers = 1; ANS( $answer->cmp() ); ENDDOCUMENT(); |
Answer Evaluation: Standard. |
- POD documentation: parserFunction.pl
- PG macro: parserFunction.pl