Writing Equation of a Line

Trying to show correctness of a linear equation for a given graphed line. The code below works if I take the initialLatex: “y=” line out. Does not work if it is in. Any advice on how to get this to work? Thanks in advance.

initialLatex: “y=”

p = patterns

sumPattern = p.sum(p.expression,p.expression)
difPattern = p.difference(p.expression,p.expression)
productPattern = p.product(p.expression,p.expression)

valid = sumPattern.matches(this.latex) or difPattern.matches(this.latex)

correct =
xyLine(this.latex).slope = -0.5 and
xyLine(this.latex).yIntercept = 3 and

correct: correct

I’ve done this is in the past but used a different approach. Here is the activity. Hopefully, this is helpful.

Thanks. Not sure I totally understand why it works. I am guessing it is actually using the graph to check. Is there a way to have it show as a Checkmark in the Dashboard as well?

The number b that is calculated in the graph component is a sum of differences between the values of correct function and the student input function at 21 different values of x. If the two functions are identical, there would be no difference, so b will be zero.

I’ve edited it so there will be a dashboard checkmark if the student is correct.

Here is the edited version

1 Like

Perfect! Thank you for your help.

If you’d like to add a graph of the line, make sure that the CL for the graph component says

readOnly: true

Otherwise, you’ll be getting a dot on the dashboard instead of a checkmark.

Thanks. I did know that and had already done it.

1 Like

Instead of “this.latex” you’ll need to use “parseEquation(this.latex).rhs”. The issue with your pattern (with y=) is that it’s attempting to check the pattern of an expression rather against an equation. If you parse the right hand side and check that against your pattern, it should work.