I am trying to write a set of homework questions.
I would like the output to evaluate the constants but not the sum, so that I may present the homework question as something like this:
$$\sum_{n=1}^{340}(-4n^2-n+3)$$
Here's what I have:
c1 = RandomInteger[{-5, 5}];
c2 = RandomInteger[{-5, 5}];
c3 = RandomInteger[{-5, 5}];
c4 = RandomInteger[{1, 50}]*20
f[x_] := c1*x^2 + c2*x + c3
f[n]
(* 340
3 - n - 4 n^2 *)
Defer[Sum[f[n], {n, 1, c4}]]
$\sum _{n=1}^{\text{c4}} f(n)$
It seems like I am not using Defer correctly. How can I fix this?


Evaluatedoesn't work here. – Mark McClure Mar 15 '13 at 20:03With, I almost posted an answer that was exactly the same as yours when you submitted it... so I scrapped it and went ahead withWith:) Btw, what did you mean re:Evaluate? – rm -rf Mar 15 '13 at 20:07Evaluateis used for this sort of thing, e.g.Plot[Evaluate[list],___], wherelistmight involve aTableor some such. In this problem, you can't wrapEvaluatearound thef[n]. – Mark McClure Mar 15 '13 at 20:14Evaluatewon't work in this case because it is too deep in the expression. – rm -rf Mar 15 '13 at 20:16