Forums

Search results: 135

I would like to be able to have a list of zero, one or two linear equations (like:  x=2, x=4) be entered and checked.  I can get one equation to work, but when trying to use a list, I am unsuccessful.  How can this be done?  Below is the code I am using 

Thanks, 
Mary Cameron

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"answerHints.pl",
"compoundProblem.pl",
"problemRandomize.pl",   # to get more problem practice
"parserImplicitPlane.pl",    # for VA and HA linear equations
);
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
ProblemRandomize(when => "Correct", onlyAfterDue => 0);
Context("Numeric");
##############################  Setup

# Choose two different vertical asymptotes
@va = ();
$va[1] = random(-9,9,1);   
do {   $va[2] = random(-9,9,1);  }  until ( $va[1] != $va[2]) ; 

$denom = Formula( "x^2 - ($va[1] + $va[2]) * x + $va[1] * $va[2]"  ) -> reduce ( "(-x)-y" => 0, "(-x)+y" => 0 );
$f = Formula("1/$denom"); 

@answers = ();
################### The following WORKS -- checking just ONE linear equation:
#Context("ImplicitPlane")->variables->are(x=>"Real",y=>"Real");
#$v1 = ImplicitPlane("x=$va[1]")  ;  # vertical asymptote equation
#$answers[1] = ImplicitPlane("x=$va[1]")  ;  # vertical asymptote equation  WORKS

#$answers[1] = ImplicitPlane( $v1 )  ;              # also works (if put $v1 defined before this)

################### The following FAILS -- Want to check Two linear equation answers as a list of two linear equations
Context("ImplicitPlane")->variables->are(x=>"Real",y=>"Real");
$v1 = ImplicitPlane("x=$va[1]")  ;  # vertical asymptote equation
$v2 = ImplicitPlane("x=$va[2]")  ;  # vertical asymptote equation
$answers[1] = List( $v1, $v2  );

################### more FAILURES
#$answers[1] = List (   ImplicitPlane( $v1 ) ,  ImplicitPlane( $v2 ) );    #  FAILS Can't locate object method "blank" via package "ImplicitPlane::formula"
#$answers[1] = List (   $v1, $v2 );                                #  FAILS ... "blank"
#$answers[1] = List (   "$v1" );                                 #  also FAILS with just one... "blank"
#$answers[1] = List (   "x=$va[1]",   "x=$va[2]"   );   # FAILS ... "blank"
#$answers[1] = List (  $va[1],   $va[2] );     # correct answers are like 4, 5  rather than "x=4", and "x=5".
#$answers[1] = List (  "$va[1]",   "$va[2]" );     # same problem here -- 4,5 is correct "

$ans_eval[1] = $answers[1] ->cmp();
#################################  Text #1
Context()->texStrings;
BEGIN_TEXT
${BBOLD}Part 1 of 3:${EBOLD}
Enter the equation(s) for the vertical asymptotes of \(  f(x) = \displaystyle $f \)
$BR If there is more than one vertical asymptote, separate the equations with commas.
$BR If there are no vertical asymptotes, enter "NONE"
$BR  The equations for the vertical asymptotes of \( f(x)  \) are
\{ ans_rule(20) \}
END_TEXT
################################  Answers #1
Context()->normalStrings;
ANS( $ans_eval[1] );



ENDDOCUMENT();


I want to have students enter "P'(t)=k * P(t)".

I found this thread by two of our esteemed PREP2014 moderators: http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2816

I downloaded the file parserFunctionPrime.pl found there, put it in the templates/macros folder, and still can't get it to work.  But maybe the problem is somewhere else.  The pink screen of death says something about illegal function name P' though.  I'm trying to do implicit plane and P'(t) and I'm not really sure about either thing.  My backup option is to turn it into multiple choice so that they don't have to enter it.  

Thanks for any help!
---------------------------------------------------

loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",
   "AnswerFormatHelp.pl",
 "parserImplicitPlane.pl",
# "parserFunction.pl",
 "parserFunctionPrime.pl",
   #"source.pl",        # allows code to be displayed on certain sites.
   #"PGcourse.pl",      # Customization file for the course
);

##############################################################

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

##############################################################

$a = random(2,6,1);
$b = random(100,1000,100);
$c = Compute($a*3);

Context("Numeric");


Context()->variables->add(t =>'Real');
Context()->variables->remove("x");

$ans1 = Compute("$b*8");
$ans2 = Compute("$b*2^(t/$a)");
$ans3 = Compute("$b*2^(19/$a)");

Context("ImplicitPlane");

parser::FunctionPrime->Enable();

 Context()->variables->remove("x","y","z");
Context()->variables->add(t =>"Real", k=>"Real", C=>"Real");
parserFunction("P(t)"=>"t**2 + sin(t)");
parserFunction("P'(t)"=>"2 t +cos(t)");
  $diffeq = ImplicitPlane("P'(t) =  k * P(t) ");

##############################################################

Context()->texStrings;
BEGIN_TEXT

The following problem is an example of exponential growth/decay (in this case, growth).  All these types of functions have the general form \(y=Ce^{kt}\), where \(t \) is time, \( C\) is the initial value, \(y\) is the value of the function at any time \(t\), and \(k\) is called the growth (or decay) constant.  (Note that interest compounded continuously has the same form).  $PAR

If we use the more customary variable names for exponential growth problems, \(P(t)=P_0 e^{k t} \), then what differential equation does this function \(P(t) \) satisfy?  Your answer should include some combination of \(P(t), P'(t), k, C, t, e\) and it's an equation, so also \( = \). (You can find this in the first few pages of Section 5.1 in your textbook if you don't remember).
\{ans_rule\} \{AnswerFormatHelp("equations") \}

----------------------------------------------------------------------
# I've redacted unedited stuff from an exponential growth problem in the library, but can but it back in if you want to see it.
-----------------------------------------------------------------------

ANS($diffeq->cmp);

ANS( $ans1->cmp() );
ANS( $ans2->cmp() );
ANS( $ans3->cmp(tolType=>'absolute', tolerance=>1) );


ENDDOCUMENT();        

For your first example, the usual approach is to use a list for part (b) so that the student enters the solutions as a comma-separated list of complex numbers. This is easier to code in a number of ways, and it can automatically provide the student with some hints about what is wrong (these can be controlled by the problem author). So I'd stick with that approach there.

For your second example, it would be possible to do that using a multi-part (sometimes referred to as a "compound") problem. This is an advanced technique that will not be covered in detail in this workshop. The tools for doing this are still actively being developed.

One option that doesn't require multi-part problems would be to allow the student to enter the array in a single large rectangle either using the MathObject matrix notation (brackets around comma-separated entries for the rows, with rows separated by commas and enclosed in brackets), or as an array of numbers separated by spaces and newlines that you turn into an array by hand within a custom answer checker. The latter would require a little extra work, but is probably preferable.

Here's one version that might do what you need:

    loadMacros("contextArbitraryString.pl");
    
    Context("ArbitraryString");
    
    $A = Matrix([1,2,3],[4,5,6]);
    
    Context()->texStrings;
    BEGIN_TEXT
    \($A\) = \(\Bigg[\) \{ans_box(4,12)\} \(\Biggr]\)
    END_TEXT
    Context()->normalStrings;
    
    ANS(Compute("1 2 3~~n4 5 6")->cmp(checker => sub {
      my ($correct,$student,$ans) = @_;
      my $M = $student->value;
      $M =~ s/  +/ /g;                                 # remove multiple spaces
      $M =~ s/(~~n|^) /~~1/g; $M =~ s/ (~~n|$)/~~1/g;  # remove leading and trailing spaces
      $M =~ s/~~n~~n+/~~n/g;                           # remove blank lines
      $M =~ s/^~~n+//; $M =~ s/~~n+$//;                # remove leading and trailing blank lines
      my @M = map {[split(/ /,$_)]} split(/~~n/,$M);   # break into an array of arrays
      $M = Matrix(@M);                                 # form MathObject matrix
      $ans->{preview_latex_string} = $M->TeX;          # format the answer preview
      $ans->{correct_ans_latex_string} = $A->TeX;      # format the correct answer 
      return $A == $M;                                 # check the answers
    }));
You can paste this into the Interactive Problem Lab to see how it works (or insert it into a problem file ad add the problem to a set). The main idea is that you get the student's answer as a string and then manipulate that string to form a MathObject Matrix. That will already perform some error checking (like that the rows are the same length and that the entries are numbers).

In any case, this is a starting point for that type of answer.

I have been studying how to write a compound problem, and have found out that it might solve one of the difficulties I have been having. However, there is one minor nuisance with the way it's written.

Once the student answers the first part of the problem, and clicks on "Submit", the grading for the first part and the (as yet unanswered) second part appears. Is there a way to hide this box until after the student has completed the second part?

Attachment Screen_Shot.jpg

WeBWorK Problems -> compoundProblem.pl -> Re: compoundProblem.pl

by Ted Shifrin -
Hi, Mike. Sorry about the delay -- I had been expecting an email when there was a response. I think we last updated about 2 or 3 years ago; it's always a scary thing for our IT folks to update :) We're earlier than 2.7 for sure.

But please do send me the version you're using and let me try. If nothing else, it will give us impetus to upgrade in December when classes are over.

Thanks!!

WeBWorK Problems -> compoundProblem.pl -> Re: compoundProblem.pl

by Michael Gage -
Hi Ted,

What version of WeBWorK do you have now?  If you have webwork 2.7
I can send you the version of compoundProblems that I'm working on now
(and using it in my classes this semester) and you can help debug it. :-)
It works pretty well for the students but I'm still working on making it easier to
write the problems.

The version of WeBWorK is at the bottom of each page in small type if you are using version 2.6 or later.  If there is no version you are using 2.5 or earlier and my compoundProblems might or might not work for that.

-- Mike

WeBWorK Problems -> compoundProblem.pl

by Ted Shifrin -
Dear Mike, Davide, et al.:

Several years ago when you upgraded, compoundProblem.pl stopped working correctly and Mike gave me a klugy fix that allows me to continue using the problems I've authored. I am still having to tell students to erase the answers that appear in the next page's boxes and scoring is all messed up (although I do believe that the final score is right if someone gets 100%).

Any chance that this will get fixed before I retire (approximately a year from now) and want to bequeath you all my problems for multivariable and linear algebra? Or has it been fixed in the latest version and do we need to upgrade here at UGA?

Thanks!


WeBWorK Main Forum -> Designating Special Characters

by Spyro Roubos -
Hello,

I know there are special ways of writing certain characters that would otherwise confuse TeX or Perl like $DOLLAR for $ and $PERCENT for %.

I was wondering how complicated is it to add others.

I ask this because our textbook uses "~" as the negation symbol unfortunately, and this has very odd effects when passing it through an answer checker or even just writing is a non-TeXed string (like to have in a pop-up menu).  Since I'm attempting to use that in a pop-up menu, I don't have the option of just using \(\sim \).

My question is: Is there an easy way of designating special characters so that they're read just as they are and not as a command?

Or as a compromise, at least display the forbidden symbol in the "answer preview", meaning: it would say something like "neg. p" in the problem, yet display properly as "~p".

Thank you,
Spyro Roubos


Here is my problem below, what I'd like would be to have $np = "~p";

# DeMorgan's Rules

########################################################################

DOCUMENT();      

loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",
   "parserPopUp.pl",

   #"source.pl",        # allows code to be displayed on certain sites.
   #"PGcourse.pl",      # Customization file for the course
);


# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

$showPartialCorrectAnswers = 1;


##############################################################
#
#  Setup
#
#
Context("Numeric");

$p = "p";   $np = "$neg. p";
$q = "q";   $nq = "neg. q";

$And = "˄";
$Or = "˅";
$Neg = "neg.";

$popup1 = PopUp(["?", $p, $np, $q, $nq], $p);
$popup2 = PopUp(["?", $And, $Or], $Or);
$popup3 = PopUp(["?", $p, $np, $q, $nq], $q);

$popup4 = PopUp(["?", " ", $Neg], $Neg);
$popup5 = PopUp(["?", $p, $np, $q, $nq], $np);
$popup6 = PopUp(["?", $And, $Or], $And);
$popup7 = PopUp(["?", $p, $np, $q, $nq], $nq);

##############################################################
#
#  Text
#
#

Context()->texStrings;
BEGIN_TEXT

Consider the compound statement: $BR $BR
Your satisfaction is guaranteed or you get your money back.
$BR $BR
Let $BBOLD \(p\) $EBOLD = "Your satisfaction is guaranteed" and $BBOLD \(q\) $EBOLD = "You get your money back".  Translate the compound statement into symbols using the drop-downs: 
$BR $BR
\{ $popup1->menu() \} \{ $popup2->menu() \} \{ $popup3->menu() \}
$BR

Rewrite this as an equivalent statement in symbols using DeMorgan's Rules: $BR $BR

\{ $popup4->menu() \} \(\big(\) \{ $popup5->menu() \} \{ $popup6->menu() \} \{ $popup7->menu() \} \(\big)\)

END_TEXT
Context()->normalStrings;

##############################################################
#
#  Answers
#
#

ANS( $popup1->cmp() );
ANS( $popup2->cmp() );
ANS( $popup3->cmp() );
ANS( $popup4->cmp() );
ANS( $popup5->cmp() );
ANS( $popup6->cmp() );
ANS( $popup7->cmp() );
 
ENDDOCUMENT();        

WeBWorK Main Forum -> Logic Context?

by Spyro Roubos -
Hello,

I'm creating problems for a Mathematical Logic homework set, and I'd like to have problems where students translate compound statements in English into symbolic form using given simple statements p, q, r.

Right now, (from other suggestions in the forum), I'm using string objects, overriding all error messages that might be confusing to students with either vague ones (like "This is incorrect") or more relevant ones.

I'm using /\ for "And", \/ for "Or", -> for "If/then", ~ for "Not".

Using the backslash in answers produces really odd results as I imagine this is messing with the parser.  It'll mark correct answers correct (happy about this), ..but it removes all backslashes from the student's answer and shows parts of their answer preview in red.

I'm wondering how doable making a simple logic parser would be with the symbols as above or if there's some special way of representing a backslash (like how $ is $DOLLAR).  A parser would be a lot nicer for the students (accepting spaces, ignoring extraneous parentheses, etc.).

Again, I want to reiterate, the problem 'works'.. it just has odd results I'd like to avoid if possible.

I've put the coding of my problem below.

Thank you,
Spyro Roubos

=======================

# Write the following statement in Symbolic Notation - Decide on Parentheses

########################################################################

DOCUMENT();      

loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",
   "parserAutoStrings.pl"

   #"source.pl",        # allows code to be displayed on certain sites.
   #"PGcourse.pl",      # Customization file for the course
);


# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;


##############################################################
#
#  Setup
#
#
Context("Numeric");

Context()->strings->clear;
Context()->constants->clear;
Context()->variables->clear;
Context()->functions->clear;
Context()->operators->clear;
Context()->parens->clear;

Context()->{error}{msg}{"Variable '%s' is not defined in this context"} =
         "This is incorrect.";

Context()->{error}{msg}{"Unexpected character '%s'"} =
         "This is incorrect.";
    Context()->{error}{msg}{"'%s' is not defined in this context"} =
         "This is incorrect.";

AutoStrings();


$C1 = String("p\/(q/\r)");
$C2 = String("(p\/q)/\r");
$C3 = String("(p\/q)/\~r");
$C4 = String("~p/\~q");
$C5 = String("~(p/\q)");

##############################################################
#
#  Text
#
#

Context()->texStrings;
BEGIN_TEXT


Consider the following simple statements:
$BR $BR
p = "We need to do the laundry" $BR
q = "We need to go grocery shopping" $BR
r = "We need to stop for gas" $BR $BR

Represent the following compound statements using symbols.  Use the forward and back-slashes on your keyboard to make "And" and "Or".  The ~ is to the left of "1" on your keyboard.  Use -> for the "Conditional".  $BBOLD Do NOT use spaces in your answer here. $EBOLD  Use parentheses where appropriate.

$BR $BR

We need to do the laundry, or we need to go grocery shopping and we need to stop for gas.: \{ans_rule(30)\}

$BR $BR

We need to do the laundry or we need to go grocery shopping, and we need to stop for gas.: \{ans_rule(30)\}

$BR $BR

We need to do the laundry or we need to go grocery shopping, but we do not need to stop for gas.: \{ans_rule(30)\}

$BR $BR

We do not need to do the laundry and we do not need to go grocery shopping.: \{ans_rule(30)\}

$BR $BR

It's false that we need to do the laundry and we do need to go grocery shopping.: \{ans_rule(30)\}

END_TEXT
Context()->normalStrings;

##############################################################
#
#  Answers
#
#

ANS( $C1->cmp);
ANS( $C2->cmp);
ANS( $C3->cmp);
ANS( $C4->cmp);
ANS( $C5->cmp);


ENDDOCUMENT();