################################################################ # # Example showing how to use the Parser to create functions you # can call from perl, to substitute values into a formula, and to # convert a formula to a form that can be used in graphics generated # on the fly. # DOCUMENT(); # This should be the first executable line in the problem. loadMacros( "PG.pl", "PGbasicmacros.pl", "PGanswermacros.pl", "PGgraphmacros.pl", "Parser.pl", "parserUtils.pl", ); TEXT(&beginproblem); ############################################## # # The setup # Context('Vector'); Context()->variables->add(a => 'Real', b => 'Real'); $a = non_zero_random(-4,-1,1); $b = non_zero_random(-3,3,1); # # The function to plot # $f = Formula("ax^2 + by"); # the function to display # # Traces to show # $x = non_zero_random(-1,1,1); $y = non_zero_random(-1,1,1); # # Graph domain and size # ($xm,$xM) = (-2,2); ($ym,$yM) = (-2,2); ($zm,$zM) = (-5,5); $size = [200,300]; $tex_size = 350; ############################################## # # The plot defaults # @Goptions = ( $ym,$zm,$yM,$zM, # dimensions of graph axes => [0,0], grid => [$yM-$ym,$zM-$zm], # number of grid lines size => $size # pixel dimension ); @imageoptions = (size=>$size, tex_size=>$tex_size); $xdomain = "x in <$xm,$xM>"; #$ydomain = "y in <$ym,$yM>"; # plot_functions only handles variable x $ydomain = "x in <$ym,$yM>"; $plotoptions = "using color:red and weight:2"; # # Make the traces # $fx = $f->substitute(x=>$x, a=>$a, b=>$b, y=>'x')->reduce; # must have variable x $Gx = init_graph(@Goptions); plot_functions($Gx,"$fx for $ydomain $plotoptions"); $Xtrace = Image($Gx,@imageoptions); $fy = $f->substitute(y=>$y, a=>$a, b=>$b)->reduce; $Gy = init_graph(@Goptions); plot_functions($Gy,"$fy for $xdomain $plotoptions"); $Ytrace = Image($Gy,@imageoptions); # # Make the table of images # @rowopts = (indent=>0, separation=>30); $Images = BeginTable(). AlignedRow([$Xtrace,$Ytrace], @rowopts). AlignedRow(["Trace for \(x=$x\)","Trace for \(y=$y\)"], @rowopts). EndTable(); ############################################## BEGIN_TEXT The graphs below are traces for a function \(f(x,y)\) at \(x=$x\) and \(y=$y\). $PAR $Images $PAR If \(f(x,y) = \{$f->TeX\}\) then \(a\) = \{ans_rule(6)\} and \(b\) = \{ans_rule(6)\}. END_TEXT ################################################## ANS(std_num_cmp($a)); ANS(std_num_cmp($b)); ################################################## ENDDOCUMENT(); # This should be the last executable line in the problem.