WeBWorK Problems

functions in inequality answers

functions in inequality answers

by Joel Trussell -
Number of replies: 0
I'm writing a problem on Laplace transforms and have asked the student to give the domain of convergence for a problem. the answer should be Re(s)>0
where I have declared s as a complex value
Context("Inequalities");
Context()->variables->are(
s=>"Complex"
);
$answerf = Inequality("Re(s)>0");

I get the error
Function 'Re' is not allowed in this context

The entire code is given below

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGunion.pl",
"parserFunction.pl",
"answerHints.pl",
"parserAssignment.pl",
"parserFormulaUpToConstant.pl",
"contextInequalities.pl"
);

TEXT(beginproblem());


#############################
# Setup1

Context("Complex");
Context()->variables->are(
s=>"Complex",
t=>"Real", dt =>"Real"
);
Context()->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
},
);
parserFunction("u(t)" => "step(t)");

$a = random(1,9,1);

$ft = Formula("$a");

$answera = Compute("$ft * e^{-s*t} * dt");
$answerb = Compute("0");
$answerc = Compute("INFINITY");
$answerd = Compute("$a/(-s) * e^{-s*t}");
$answere = Compute("$a/s");

$reals= Re(Compute($a));

#############################
# Main text1

Context()->texStrings;
BEGIN_TEXT
The Laplace transform of the function \(f(t)\) is defined by the integral
\[
F(s) = \int_0^\infty f(t) e^{-st}dt
\]

where \(s = \alpha + j\omega\) is a complex number. All of our functions will be defined only on the non-negative domain, \([0,\infty]\). We will usually emphasize this by including the step function, as \(f(t) = cos(2\pi t) u(t)\). In any case, the Laplace integral is always defined with a lower bound great than or equal to zero.
$PAR
Note that the Laplace transform, \( F(s)\), is a function of \(s\). We must make sure that the function is well-defined so the function actually exists. Let's take a look at an example to show how this works.
$PAR
Consider the function \(f(t) = u(t)\), the unit step function. The transform is defined by
\[
F(s) = \int_0^\infty f(t) e^{-st}dt = \int_0^\infty e^{-st}dt
\]

since \( u(t)=1\), for all \(t \geq 0\). This is an easy integral to compute, as
\[
F(s) = \frac{ e^{-st}}{-s}|_0^\infty
\]

This may seem straightforward, but we need to check to see if the function is defined at the limits of the integral. At the lower limit, it is easy
\[
\frac{ e^{-st}}{-s}|_0 = \frac{ e^{-s0}}{-s} = \frac{e^{-s0}}{-s} = \frac{-1}{s}
\]

but at the upper limit the funciton is not so clear. We have to take the limit as \(t \longrightarrow \infty\). This limit depends on the value of \(s = \alpha + j\omega\). We know from Euler's formula that
\[
e^{-st} = e^{(\alpha + j\omega)t} = e^{\alpha t }e^{ j\omega t}.
\]

We know that the magnitude of \(e^{ j\omega t}. = 1\), so we are concerned only with the behavior of the limit of the real part, \( \lim_{t\rightarrow \intfy} e^{\alpha t } \)
$BR But we know this limit exists only if \(\alpha > 0\) and the limit is zero. This can also be stated as \(Re(s) > 0\), or the real part of \(s\) is greater than zero.
$BR So the evaluation of integral yields
\[
F(s) = \frac{ e^{-st}}{-s}|_0^\infty = \frac{1}{s}
\]

With this computation complete, let's look at a minor modification.

\{ BeginList('OL', type=>'a') \}

$ITEM Set up an integral for finding the Laplace transform of \( f(t) = $ft u(t)\).
$BR
$BR
\( \displaystyle F(s) = {\mathcal L}\left\lbrace f(t) \right\rbrace = \int_A^B \)
\{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}
$BR
$BR
where \( A = \) \{ ans_rule(5) \} and \( B = \) \{ ans_rule(5) \}.

$ITEMSEP
$ITEM Find the antiderivative and limits corresponding to the previous part.
$BR
$BR
\{ ans_rule(20) \}\( {\Huge |}_A^B \)

$ITEMSEP
$ITEM Evaluate appropriate limits to compute the Laplace transform of \( f(t) \):
$BR
$BR
\( F(s) = {\mathcal L}\left\lbrace f(t) \right\rbrace = \)
\{ ans_rule(20) \}

END_TEXT
Context()->normalStrings;


##############################
# Answer evaluation1

$showPartialCorrectAnswers = 1;

ANS( $answera->cmp()
->withPostFilter(AnswerHints(
Formula("$ft * e^(-s*t)") => "Don't forget the differential dt"
))
);
ANS( $answerb->cmp() );
ANS( $answerc->cmp() );
ANS( $answerd->cmp(upToConstant=>1) );
ANS( $answere->cmp() );


##############################
# Setup2

Context("Inequalities");
Context()->variables->are(
s=>"Complex"
);
$answerf = Inequality("Re(s)>0");


##############################
# Main text2

Context()->texStrings;
BEGIN_TEXT

$ITEMSEP
$ITEM Where does the Laplace transform you found exist? In other words, what is the domain of \( F(s) \)?
$BR
$BR
\{ ans_rule(20) \}
\{ AnswerFormatHelp("inequalities") \}

\{ EndList('OL') \}
END_TEXT
Context()->normalStrings;


##############################
# Answer evaluation2

ANS( $answerf->cmp() );

ENDDOCUMENT();