Use xyLine to type proper equations?

Bryn asked this forever ago, and I doubt he cares about the answer anymore, but I would find an answer useful. I didn’t know how to bump his post to relevancy again. Does anyone know how to make it so the correct input for this example has to be “y=3x”

Is there a way to use xyLine that means students must type proper equations?

Questions

Bryn

May '18

I have an expression input where I ask students to give the equation of a line with a gradient of 3.

In order to ascertain correctness, I have code like this:

myLine = xyLine(exp.latex)
correct: myLine.slope = 3

The problem is that if a user types in “3x” then this will be marked as correct but really I don’t want to accept this.

Is there a way I could test to see if something was a well formed equation (or at least whether there was an equals sign in the string)?

I know I can also include initialLatex: "y = " but it still irks me that a student could take 3x, and perhaps Ialso want them to be able to enter in a different form like y - 3x = 10

I think I asked it before there was the ability to parse equations with a lhs and rhs. Nowadays I would probably use xyLine combined with checking that the lhs and rhs are defined.

Sigh. Okay. From simpleFunctions vs. xyLine vs. parseEquation
the only one I really understood was xyLine. I just want to make a slide where students enter the equation of a proportional relationship. I can’t understand the code enough from the other examples to do this , but the `correct: myLine.yIntercept=0’ made sense to me.
I don’t suppose parse equation code is easy enough to give me an example for a correct input of the form y=kx where k is any rational number?

You could do something like this in the math input component:

myLine = xyLine(this.latex)
eqn = parseEquation(this.latex)

correct: myLine.yIntercept = 0 and isDefined(eqn.lhs) and isDefined(eqn.rhs)

So that will force an equation to be there. If you want to disallow an equation like 3x = y then you could also add this into your correctness condition

and eqn.lhs = `y`

And if you want to disallow the possibility of y = 0 (although technically this matches your specification above) then you could also have

and not(myLine.slope = 0)
1 Like

Thank you, thank you!!

1 Like

You can combine slope and y-intercept and your lhs condition, so for y=3x:

myLine= xyLine(this.latex)
eqn= parseEquation(this.latex)

correct: myLine.slope=3 and myLine.yIntercept=0 and eqn.lhs =`y`
1 Like