WeBWorK Main Forum

small number showing and computed asa zero

small number showing and computed asa zero

by Joel Trussell -
Number of replies: 1
A student entered numbers which should have been in units of microFarads, i.e., 5E-6 instead of 5
this will clearly lead to a wrong answer, but the question is when he previews the answer it shows zeros for all of the numbers in a formula.
I tried the answer using 5*10^(-6) and it shows as 4.10^(-6) in answer preview column but zero in the entered column
5*10^(-4) will show as 5*10^(-4) in preview and 0.0005 in Entered.
What is going on and how do I avoid it?
code below

# DESCRIPTION
# Problem for 'NCSU ECE331 Hambley 6Ed P3.24'.
# WeBWorK problem written by H. J. Trussell, <hjt@ncsu.edu>
# ENDDESCRIPTION

## DBsubject(Electrical Engineering)
## DBchapter(Chapter 3 Inductance and Capacitance)
## DBsection(Section 3.1 Capacitances in Series and Parallel)
## Institution(North Carolina State University)
## Author(H. J. Trussell)
## TitleText1('Electrical Engineering : Principles and Applications')
## AuthorText1('Hambley, Allan R.')
## EditionText1('6')
## Problem1('3.24')
## Keywords('capacitor','combine','synthesize')
## Resources('ECE331_Hambley_Ch3_3-24.png',)



DOCUMENT();

loadMacros("PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGgraphmacros.pl",
"extraAnswerEvaluators.pl",
"PGauxiliaryFunctions.pl",
"PGgraphmacros.pl",
# "parserPopUp.pl",
"MathObjects.pl",
"PGcourse.pl",
"AnswerFormatHelp.pl",
"answerHints.pl",
);

TEXT(beginproblem());

Context("Numeric");

Context("Numeric")->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
},
);

Context()->flags->set(
tolerance =>0.01,
tolType => "relative",
);

Context()->variables->are(t=>'Real');
Context()->{format}{number} = "%.4f#";
#Initialize element values, to be changed for each question
$C1av=random(1,20,1); #uF
$C2av=random(1,20,1); #uF
$C3av=random(1,20,1); #uF

$C1bv=random(1,20,1); #uF
$C2bv=random(1,20,1); #uF
$C3bv=random(1,20,1); #uF
$C4bv=random(1,20,1); #uF
$C5bv=random(1,20,1); #uF
## Debugging Code Parameters From Textbook
#$C1av=2;$C2av=1;$C3av=2;
#$C1bv=12;$C2bv=5;$C3bv=4;$C4bv=4;$C5bv=2;


$Ceq1v=Real($C2av+1/(1/$C1av+1/$C3av));
$Ceq2v=Real($C2bv+1/(1/$C1bv+1/($C5bv+1/(1/$C3bv+1/$C4bv))));
#Context()->texStrings;
BEGIN_TEXT
$BBOLD Problem is related to P3.24 in "Electrical Engineering : Principles and Applications 6Ed" (Hambley). $EBOLD $BR
\{image("ECE331_Hambley_Ch3_3-24.png",height=>500, width=>400)\} $BR
$PAR
Determine the equivalent capacitance for the two circuits above. $BR
$PAR
$BBOLD a) $EBOLD Given \( C_1=$C1av \mu F, C_2=$C2av \mu F, C_3=$C3av \mu F. \)
$BR
\( C_{eq} \) = \{ans_rule(10)\} \( \mu F \) \{ AnswerFormatHelp("numbers") \} $BR
$PAR

$BBOLD b) $EBOLD Given \( C_1=$C1bv \mu F, C_2=$C2bv \mu F, C_3=$C3bv \mu F, C_4=$C4bv \mu F, C_5=$C5bv \mu F. \)
$BR
\( C_{eq} \) = \{ans_rule(10)\} \( \mu F \) \{ AnswerFormatHelp("numbers") \} $BR
$PAR

END_TEXT
Context()->normalStrings;




##############################
# Answer evaluation



$showPartialCorrectAnswers = 1;
ANS($Ceq1v->cmp());
ANS($Ceq2v->cmp());
##############################
# Solution

Context()->texStrings;
BEGIN_SOLUTION;
$PAR
$BBOLD SOLUTION $EBOLD
$PAR
a) \( C_{eq} = $Ceq1v \mu F \) $BR
b) \( C_{eq} = $Ceq2v \mu F \) $BR
END_SOLUTION
Context()->normalStrings;

ENDDOCUMENT();
In reply to Joel Trussell

Re: small number showing and computed asa zero

by Joel Trussell -
one of our TAs found the problem

"Context()->{format}{number} = "%.4f#";
limits computation to 4 decimal places

sorry about that