WeBWorK Problems

Extra information appearing in graph

Extra information appearing in graph

by James Morski -
Number of replies: 2

I have run in to the following issue. I have created dynamicimages for the below problem. Each of the exponential portions renders correctly, but some extra information gets added to the graph in some cases (see attached).

When I re-seed, the issue sometimes appears and sometimes does not. I know that I could alter the domain for the functions, but this doesn't really solve the issue. I have also messed around with different steps in the graph (using
($gr->fn)[0]->steps(2000);), but this doesn't fix it either.


Here is my code. Can anybody view a problem?


Thanks!
James

## DESCRIPTION
## Algebra, Exponential functions
## ENDESCRIPTION


## DBsubject()
## DBchapter()
## DBsection()
## Date(06/26/2017)
## Institution(Colorado Community College System)
## Author(James Morski)
## Static(1)
## MO(1)
## KEYWORDS('algebra','exponential functions')


###########################
# Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"parserAssignment.pl",
"AnswerFormatHelp.pl",
"PGML.pl",
"PGgraphmacros.pl",
"parserPopUp.pl",
"PGcourse.pl",
"contextLimitedPoint.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;


##########################
# Setup

$a=random(-5,-2,1);
$b=random(.15,.85,.1);
$c=random(1,5,1);
$d=random(1,5,1);


$gr = init_graph(-10,-10,10,10,
axes=>[0,0],
grid=>[10,10],
size=>[600,600]
);

$gr1 = init_graph(-10,-10,10,10,
axes=>[0,0],
grid=>[10,10],
size=>[600,600]
);


$gr2 = init_graph(-10,-10,10,10,
axes=>[0,0],
grid=>[10,10],
size=>[600,600]
);

$gr3 = init_graph(-10,-10,10,10,
axes=>[0,0],
grid=>[10,10],
size=>[600,600]
);

$gr4 = init_graph(-10,-10,10,10,
axes=>[0,0],
grid=>[10,10],
size=>[600,600]
);

add_functions($gr, "($a($b)^x) for x in <-10,10>" .
" using color:blue and weight:2");

add_functions($gr1, "($a($b)^(x+$c)-$d) for x in <-10,10>" .
" using color:blue and weight:2");

add_functions($gr2, "(-$a($b)^(x)-$c) for x in <-10,10>" .
" using color:blue and weight:2");

add_functions($gr3, "($a($b)^(x-$d)-$c) for x in <-10,10>" .
" using color:blue and weight:2");

add_functions($gr4, "($a($b)^(x+$d)+$c) for x in <-10,10>" .
" using color:blue and weight:2");

Context("Numeric");
$popup1 = PopUp(
["?","A","B", "C", "D"], "C",
);

$popup2 = PopUp(
["?","x","y"], "y",
);


$fun=("$a($b)^x");

$ans1=("$a($b)^(x+$d)+$c");



$ans2 = ("$c");


#################################
# Main text

BEGIN_PGML


The graph of `f(x)=[$fun]` is given below (click on graph to enlarge):


>>[@ image(insertGraph($gr), width=>300, height=>300), @]*<<



Let `g(x)` be the transformation of `f(x)` up `[$c]` units and left `[$d]` units. Which of the following graphs represents the graph of `g(x)`? [_________________]{$popup1}


>>A. [@ image(insertGraph($gr1), width=>200, height=>200), @]* B. [@ image(insertGraph($gr2), width=>200, height=>200), @]* <<

>>C. [@ image(insertGraph($gr4), width=>200, height=>200), @]* D. [@ image(insertGraph($gr3), width=>200, height=>200), @]* <<

What is the equation for `g(x)`?

>>`g(x)`= [_________________]{$ans1} [@ AnswerFormatHelp("formulas") @]*<<

What is the horizontal asymptote of `g(x)`? Enter the equation of a line.

>>[_________________]{$popup2}=[_________________]{$ans2}<<


END_PGML

#################################
# Solution

#BEGIN_PGML_SOLUTION
#Solution explanation goes here.
#END_PGML_SOLUTION

COMMENT('Uses PGML.');

ENDDOCUMENT();

Attachment WWGraph.PNG
In reply to James Morski

Re: Extra information appearing in graph

by Davide Cervone -
The issue is probably that the values of the equations have huge magnitudes near the left of the graph. For example, with $a = -5, $b = .15; $c = 5, and $d = 5, some of the graphs have magnitudes on the order of 10^13. I don't know how the graphing library deals with values on that order, but I suspect there are numeric problems associated with that.

One solution would be only to use x values that produce reasonable sized y values. E.g.,

$m = ln(-15/$a)/ln($b);
add_functions($gr, "($a($b)^x) for x in <$m,10>" . 
" using color:blue and weight:2");

$m = ln(($d-15)/$a)/ln($b)-$c;
add_functions($gr1, "($a($b)^(x+$c)-$d) for x in <$m,10>" . 
" using color:blue and weight:2");

$m = ln(-($c+15)/$a)/ln($b);
add_functions($gr2, "(-$a($b)^(x)-$c) for x in <$m,10>" . 
" using color:blue and weight:2");

$m = ln(($c-15)/$a)/ln($b)+$d;
add_functions($gr3, "($a($b)^(x-$d)-$c) for x in <$m,10>" . 
" using color:blue and weight:2");

$m = ln((-$c-15)/$a)/ln($b)-$d;
add_functions($gr4, "($a($b)^(x+$d)+$c) for x in <$m,10>" . 
" using color:blue and weight:2");
(I didn't check the math for $m carefully, so you might want to double check that.)
In reply to Davide Cervone

Re: Extra information appearing in graph

by James Morski -
David, thanks for the reply. Yes, restricting the domain seemed to solve the problem. Thanks!