WeBWorK Main Forum

answer contains derivatives and integrals

answer contains derivatives and integrals

by Joel Trussell -
Number of replies: 3
A collage in ECE would like to ask the students to derive the differential equation for a simple circuit. The usual answer for this is something like that in the attached file. Is there a way the students can enter derivatives or indefinite integrals in their answer - such a way that it can be checked?

In reply to Joel Trussell

Re: answer contains derivatives and integrals

by Michael Gage -
You could easily check the last question (with the values in the box).  We've had good luck checking purely symbolic (but more math related) questions which could probably handle questions b -- d.  (see image attached) 

Possibly even question (a) could be handled but I would suggest that might be better suited to an essay question to be graded by hand.




Attachment 2016-05-10_20-57-47.jpeg
In reply to Michael Gage

Re: answer contains derivatives and integrals

by Joel Trussell -
I could handle all the symbolic variables except the operators. image attached. How do I insert images into the message window? 

the code is 
DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"answerHints.pl",
"parserFunction.pl",
"PGcourse.pl",
"PG.pl",
);

TEXT(beginproblem());


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


## required to use step function
Context("Complex")->functions->add(
  step => {
    class => 'Parser::Legacy::Numeric',
    perl => 'Parser::Legacy::Numeric::do_step'
  },
);
Context()->variables->add(
t=>"Real", C=>"Real", L=>"Real",  R=>"Real",  I=>"Real",  Vs=>"Real", w=>"Real",
V0=>"Real"
);

# Change tolerance to account for difference in Matlab and Webwork computations
# I don't know the problem yet

Context()->flags->set(
  tolerance => 0.001,
  tolType => "absolute",
);
parserFunction("u(t)" => "step(t)");


$answer[0] = Formula("L")->reduce;


$answer[1] = Formula("1/C")->reduce;

$answer[2] = Formula("R")->reduce;

$answer[3] = Formula("R*I + j*w*L*I - j*I/(w*C)")->reduce;
$answer[4] = Formula("V0*exp(j*pi/3)")->reduce;

$answer[5] = Formula("V0*exp(j*pi/3)/(R +  j*w*L - j/(w*C))")->reduce;


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

Context()->texStrings;
BEGIN_TEXT
This is a test problem
$PAR
\{image("RLC_Series_Circuit.png",height=>140, width=>270)\} $BR
Problem is related to Problem x.xx  in the text (for ECE303).
$PAR

$PAR For the above circuit, with \( v_s(t) = V_0 cos(\omega t + \pi/3) \) Volts, write the voltage loop equation in terms of the current \(i(t)\), using the symbolic values \( R\), \( L\), \( C\), \( v_s(t)\).  

$BR
\(\Large{ v_s(t) = }\) \{ ans_rule(10) \}\(  \Large{ \frac{di(t)}{dt} } \) +  \{ ans_rule(10) \}\( \Large{ \int i(t) dt } \)  + \{ ans_rule(10) \}\( \Large{   i(t) } \)  
\{ AnswerFormatHelp("formulas") \}

$PAR Write the corresponding phasor-domain equation. Use upper case I for the phasor current \(\tilde{I}\) and \(w\) for the frequency \(\omega\).


$BR
\( Vs = \) \{ ans_rule(40) \}
\{ AnswerFormatHelp("formulas") \}

$PAR Write the phasor representation of the voltage source \( v_s(t) = V_0 cos(\omega t + \pi/3) \) Use Vs for the phasor \(\tilde{V}_s\)


$BR
\( Vs = \) \{ ans_rule(40) \}
\{ AnswerFormatHelp("formulas") \}

$PAR Using the phasor representation of the voltage source, solve the phasor equation to obtain an expression for the phasor current, I. 


$BR
\( I = \) \{ ans_rule(40) \}
\{ AnswerFormatHelp("formulas") \}

END_TEXT
Context()->normalStrings;


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

$showPartialCorrectAnswers = 1;

ANS( $answer[0]->cmp() );
ANS( $answer[1]->cmp() );
ANS( $answer[2]->cmp() );
ANS( $answer[3]->cmp() );
ANS( $answer[4]->cmp() );
ANS( $answer[5]->cmp() );

COMMENT("MathObject version.");

SOLUTION(EV3(<<'END_SOLUTION'));


END_SOLUTION

ENDDOCUMENT();

Attachment Prob1.PNG
In reply to Joel Trussell

Re: answer contains derivatives and integrals

by Michael Shulman -
It should be possible to enter formulas containing first derivatives, at least, by declaring "dy" and "dx" (and so on) to be variables.