I am trying to make a combining like-terms activity self-checking but have never coded a self-checking math input with more than one-variable in the expression. For example, slide 1 simplifies to 11x+5y. I found some past posts with multiple variables that checked using a quadratic function but I’m wondering if there isn’t something easier I can use. Does anyone have something I can copy…any insight here is much appreciated!
I tried two methods.
Screen1: Tried using patterns
but couldn’t parse the two parts of the sum separately, @JayChow, can you comment on fixing screen 1 here?
Screen2: separated the two parts into two inputs and had Demos recombine for final expression
term1.latex will pull the first arguments in the sum pattern. Altogether it’ll look like this:
part1 = exp.parse(ref.latex).term1.latex
The tricky part here is that because you’re allowing any expression as the first term, it’ll recognize anything that is separated by the “+”
Here’s where you can parse/match the sub string to check that each term is a letter, a letter times a number, or a number.
The -y presents a different problem, where a student that enters something like 3x-y won’t have it match the sum pattern. But thats just a matter of adding some flexibility to the match pattern.
Thanks for responding…I tried what you wrote but as you said, it’s reading as correct before the y is even typed in. Do you know of any other templates for this that I can try and copy or do you have an idea? Thanks for the help.