Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16637
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: What's in an expression? |
| Date | 2014-03-11 07:16 +0000 |
| Message-ID | <lfmd8c$n6n$1@smc.vnet.net> (permalink) |
| References | <20140310083813.8DCCA6A2A@smc.vnet.net> |
| Organization | Time-Warner Telecom |
Assuming that answers are entered as strings; to exclude derivatives but
allow other alternative forms:
verifySolution[proposed_, actual_, cond_: {}] :=
StringFreeQ[proposed, {"Derivative", "'", "D["}] &&
Simplify[ToExpression[proposed] == actual, cond]
answers = {"Sin'[x]", "Derivative[1][Sin][x]",
"D[Sin[x],x]", "Cos[x]", "Sin[x]/Tan[x]"};
ToExpression /@ answers // Union
{Cos[x]}
verifySolution[#, Cos[x]] & /@ answers
{False, False, False, True, True}
If the answer must be literally the same as the intended answer:
verifySolution2[proposed_, actual_] :=
SameQ @@ (StringTrim /@ {proposed, actual})
verifySolution2[#, "Cos[x]"] & /@ answers
{False, False, False, True, False}
Bob Hanlon
On Mon, Mar 10, 2014 at 4:38 AM, <sam.takoy@yahoo.com> wrote:
> Hi all,
>
> I'm building a little Mathematica system that checks answers entered by
> students. Suppose the question is "what is Sin'[x]?" ad the student
> responds: Sin'[x] which is "correct", but not the intended answer (Cos[x]).
> I'm wondering if there is a general way to approach this sort of problem.
> In particular, is there a way to find out whether a given expression
> includes certain elements (like Derivative)?
>
> Thank you in advance,
>
> Sam
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar
Re: What's in an expression? Bob Hanlon <hanlonr357@gmail.com> - 2014-03-11 07:16 +0000
csiph-web