I am keen to be able to parse quadratic expressions like x²-7x+6 and extract the coefficients as a = 1, b = -7, c = 6.
I saw there is the parabola/conic type and so far the below is the best I have come up, but the problem for my purposes is that I don’t want students to be able to type in (x - 6)(x - 1) and have Desmos do the expansion for us.
Has anyone written some CL code that parses expanded quadratic expressions and returns the coefficients?
negate = simpleFunction(`-x`)
fn = conic(exp.latex)
a = negate.evaluateAt(fn.getCoefficient(3,1))
b = negate.evaluateAt(fn.getCoefficient(2,1))
c = negate.evaluateAt(fn.getCoefficient(1,1))
I’m not sure how to use calculus to do it in a simpler way than the five lines of code above, but actually the more fundamental issue I’m facing is that I realised I want to parse expanded expressions to extract the coefficients (it’s for correctness-checking on questions where students are required to expand brackets).
Yep I wasn’t super clear in the original question. If I ask them to expand (x - 6)(x - 1) I want them to give me the answer x²-7x+6, but if I just check that they have got the right function (which the calculus solution and conic solutions both would do) then I would end up automatically classifying them as correct if they literally just typed (x - 6)(x - 1) in the answer.
So a more extreme way around it, and probably what I’ll do rather than properly parsing is just check literally for whether the latex is x^2 - 7x + 6. But it does mean that I would mark them incorrect for 6 -7x + x^2.
I guess I was hoping someone had already done the hard job of writing code the parses expanded quadratics and extracted the coefficients.
Here are a couple examples. You can combine either your conic method or using test values to check the student answer against the correct function, combined with a structure check to see that it is in the form of a trinomial. The first two screens are more restrictive, meaning that it must see x^2 + expression + expression to be correct, and the last screen just needs to see expression + expression + expression. The problem with that being that a student could potentially write the answer as like (x-6)(x-1) + 1 + -1 and that would mark correct. The first two screens should work fine, and would only need modification if you needed it to parse ax^2 instead of just x^2. Does this do what you are looking for? Using repeat and allowNegativeTerms patterns, and Conics, to check quadratics • Activity Builder by Desmos