Hi All, I want to write some code that will give feedback to a student on their answer for factorising quadratics. So ideally their answer will be in the form (x+3)(x+1) for example. Please can anyone let me know the code for something like this - I am a relative newbie at this!
Thanks
Latex matching can be unstable (but more reliable than it used to be). The main tip is type what you want for an answer into a math input in the preview, and copy/paste it into your CL and put backticks around it.
If they’re answering in an input:
In input CL:
check= this.latex=`\left(x+3\right)\left(x+1\right)`
or this.latex=`\left(x+1\right)\left(x+3\right)`
correct: check #this will give the dashboard checkmark
Name your input, then in your note CL:
content: when not(yourInputName.submitted) ""
when yourInputNameHere.script.check "Correct"
otherwise "Incorrect"
For a more stable computational method:
In your input:
f=simpleFunction(input.latex) #turn input into a function
#evaluate it for a few different values
#and check for the presence of specific numbers
check= f.evaluateAt(-3)=0 and f.evaluateAt(-2)=1
and countNumberUsage(input.latex,3)=1
and countNumberUsage(input.latex,1)>=1
and countNumberUsage(input.latex,4)=0
correct: check
(Use the same note code as the prior reply)
countNumberUsage checks how many times a number is used. When checking for “1”, I set >= in case you want to accept a student putting (1x+3)(1x+1)
, but “4” should be not be present to mark the expanded form incorrect.
Note that countNumberUsage only accepts positive values as parameters, so this:
check= countNumberUsage(input.latex,2)=1
would be correct for 2, -2, x+2, x-2, 2x, -2x, etc., so you always want it in combination with some kind of evaluation (i.e. simpleFunction( ).evaluateAt( ) or numericValue( ) ).
Just sugestion. I like flexibility when giving equations. To make it general, solve it using quadratic formula and then ask if student’s factors match. If you want ansvers in radical form use discriminant in latex as radicand.
This algorithm works for any equation and you can create different assignments.
Hi Mirko I like your suggestion a lot. I was wondering can you give a sample code? For example if I want the answers for: x^2-x-12. Thanks in advance.
Thanks - I will certainly look into that over half term - I managed a temporary fix that works for today.
I attached example activity to graph quadratic in standard form. I calculate coefficients a, b, and c and compare them with student’s input. If they match green check. At the end they see the function graph after checking the check box.
It can be used for any other quadratic problem, because coefficients are calculated in graph frame. Even if function is entered in vertex form graph still calculate coefficients.
Hope it helps.
I kind of see what you’re doing. One suggestion I’ve seen to improve the efficiency of your code is to try to only pass calculations one way between CL and graph. In your graph CL, most of those calculations can be done in the graph. Like k, could just be defined in the graph as k=f(h)
rather than using simpleFunction in the CL. Same for all the coefficients in the graph CL. Seems easier to me to calculate in the graph.
You also don’t need to define a variable in the graph CL referencing a number in the graph, and then calling on the variable from other components. You can just call it directly from the graph. In t2, you could’ve just used x_1=g1.number(`x_1`)
.
Here’s my revised version of yours. Generally, I just #'d your code that I replaced so you can see differences side by side. A few notes, but not a lot. I also added a few folders into the graph to replace the calculations done in the CL.
This is a great help. You remember that I mentioned being new to CL. These tricks are greatly appreciated.
btw.
I am still working on check for x1 and x2 correctness.
Thanks.
Thanks for the work you put in. I may have asked the wrong question though. What if I want to check whether or not the factored form (x+3)(x-4) is correct using what you suggested:
“Just sugestion. I like flexibility when giving equations. To make it general, solve it using quadratic formula and then ask if student’s factors match. If you want ansvers in radical form use discriminant in latex as radicand.
This algorithm works for any equation and you can create different assignments.”
Aren’t x1 and x2 factors already. May be that I misunderstood. If numbers are nice roots will be integers.
Checking student’s answer would be another function to analize and if your function parameters match student’s they should get a check.
Unfortunately parsing latex is not good yet.
Other than the less stable, latex check…
check= this.latex= `(x+3)(x-4)` or this.latex=`(x-4)(x+3)`
correct: check
…otherwise the reply I gave earlier with countNumberUsage
is the only way to computationally determine a particular form.
One technical? How do you put your link in frame like you did.
Regarding countNumberUsage. This example works for positive numbers, but it doesn’t recognize negative number is this a flaw or I was doing something wrong. When I search for negative number it doesn’t match it. I even tried in desmos CL example when I change 4 to -4 and search it reports 0.
It is possible that the best way for now is to look for string match.
First, I just pasted the link in (without using the link insertion button). It just automatically does it.
Not a flaw. Entering a positive number searches for occurrences whether positive or negative. So, countNumberUsage(input.latex, 4)=1
will result in true for 4, -4, 4x, or -4x. Combining with an evaluation will address any amibiguity, except maybe the rare case of wanting 4 vs. -(-4).