## PREP 2014 Question Authoring - Archived

### problem testing function as user defined values

by Joel Trussell -
Number of replies: 0
I am creating a problem with a symbolic answer. I thought the easy way to do this would be just to create my own function X(w) = w, and use it in the answer. The Fourier transform of x(n) + x(n-1) is X(w) + exp(-j*w)*X(w). It doesn't really matter what X(w) is as long as I can evaluate it. See the code below.

DOCUMENT();

# modified to use j for i = sqrt(-1)
$complexJ =1; # 0 => i, 1 => j$I = ($complexJ)? 'j': 'i'; loadMacros( "PGstandard.pl", # Standard macros for PG language "MathObjects.pl", ($complexJ) ? "contextComplexJ.pl" : "",
#"source.pl", # allows code to be displayed on certain sites.
"PGcourse.pl", # Customization file for the course
"parserFunction.pl",
);

# DTFT of aperiodic series geometric series

TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1; ############################################################## # # Setup # # Context("Complex"); Context()->variables->are(w=>'Real'); #Context()->variables->are(n=> 'Real',w=>'Real'); #Context()->variables->remove(z); # only variables should be n and w parserFunction("X(w)" => "w");$n0 = random(1,9,1); # delay of sequence
$c1 = random(1,9,1); # gain of x(n)$c2 = random(1,9,1); # gain of x(n-$n0) #$Xp = Formula("$c1*X(w) -$c2*e**((-1)*j*w$n0)*X(w)")->reduce->with(test_at => [[0,0],[0,1],[0,2],[0,3]]); # used with two variables n and w$Xp = Formula("$c1*X(w) -$c2*e**((-1)*j*w$n0)*X(w)")->with(test_at => [[0],[1],[2],[3]]); ############################################################## # # Text # # Context()->texStrings; BEGIN_TEXT This problem is related to 4.17a in the text.$PAR
Let $$x(n)$$ be an arbitrary signal, not necessarily real valued, with Discrete Fourier transform, $$X(\omega )$$,
$BR Express the Discrete Fourier transform of the following signal in terms of $$X(w)$$,$BR Use $$w$$ for $$\omega$$(omega) to make typing easy.
$y(n) = c1*x(n) - c2*x(n-n0),$

$PAR$BR $$Y(\omega )=$$ \{ $Xp ->ans_rule(40)\} END_TEXT Context()->normalStrings; ############################################################## # # Answers # # ANS($Xp->cmp());

ENDDOCUMENT();