## WeBWorK Problems

### Answers in terms of functions

by D. Brian Walton -
Number of replies: 1
Suppose I want to write a problem involving an unspecified function and the answer needs to be expressed in terms of that function. For example, this might be a recurrence relation between function values (sequences) and I want the student to type in the recurrence relation:

f(n) = 3 f(n-1) + 2

I would probably keep "f(n) =" outside of the answer block, so the student would really only need to type 3 f(n-1) + 2.

I know that I would add n as a variable to the context. But what do I do about f? In particular, I don't want to define f as a computable function, just that it is a function.

Thanks,

- D. Brian Walton

In reply to D. Brian Walton

### Re: Answers in terms of functions

by Davide Cervone -
What you are asking for is somewhat difficult to accomplish in WeBWorK. This is because WeBWorK compares functions by evaluation, not by algebraic structure, so there would have to be a means of evaluating f(n) before WeBWorK would be able to handle it.

It is possible to use the parserFunction.pl macro library to do this, though it does present some possible (but unlikely) ways to get the answer marked correct without it being what you want.

Here is a sample code snippet that may do what you are after:

$f = Formula("3 f(n-1) + 2"); BEGIN_TEXT $$f(n)$$ = \{ans_rule(20)\}. END_TEXT ANS($f->cmp);