Coding question

What is your question with the coding? The equation shown is coded by what the arrow is pointing at, although I think the slash before the “x” is unnecessary. The general syntax for a fraction as latex is \frac{numerator}{denominator}.

I entered this equation and the check box will check green but stays an X.

Can you share a link to your activity so I can look at the rest of your code? Specifically, I’d guess it has something to do with valid.

Am I wrong or doesn’t simpleFunction need an identifier for the variables in it?

simpleFunction(“y=\frac{5}{2}x-2”,”y”,”x”)

If there is no identifier, simpleFunction() defaults to in terms of x. An equation like y=\frac{5}{2}x-2 is treated as f(x)=\frac{5}{2}x-2, so no variable arguments are necessary. Conversely, 2y=\frac{5}{2}x-2 is an implicit equation and can’t be treated as a function because there is no isolated variable.

Oh. Then I don’t see any problem here!

I tried this and got a lot of red flags.

This works for non fractions: f1 = simpleFunction(y=-5x+3)

but I cant code to correct the problems y = 5/2x - 2

I have tried various versions of what people have listed?

This is the line of code that works for non fraction answers.

f1 = simpleFunction(‘y=-5x+3’)

Here is my activity

The reason it’s not working is the xTerm pattern is specifying a number:

xTerm = p.anyOf(X, p.product(p.number,X) , p.negative(X))

Updating it to the following should allow fractional slopes:

pFraction = p.fraction(p.integer, p.integer)
xTerm = p.anyOf(
   X, 
   p.product(p.anyOf(p.number, p.negative(pFraction), pFraction),X),
   p.negative(X))

(returns are just for readability, but aren’t necessary)

Thanks for that info,

First time doing an activity builder like this.

What lines do I type this on?

Just type over the current line?

Huh? That doesn’t make sense. It should work, but as @Daniel_Grubbs said it is unnecessary

Edit: Oh, you need “`” things

What’s fraction, anyOf, product, or negative? Are the sources/functions for lists?

Those are definitions for patterns, which can be used in an indeterminate number of combinations to analyze and parse latex expressions.

Here’s an intro series.

Sorry, missed this one. Yes, just replace the xTerm line with the new set of code I provided. Poaching and editing other folks’ code is a great way to jump in and learn!

Thanks

I got that work.

I do have another question.

When the first value is an integer and the second is a fraction, do I need to adjust that line?

For example if the answer is y = 2x - 3/2

or if the answer has 2 fractions, such as y= 1/2x+ 3/2

Ah yes. Similarly, your constantTerm is defined as p.number , which includes integers, decimals, and mixed numbers, but not fractions. This is because the fraction pattern is more accurately a rational expression, rather than a number. So we have to similarly include options:

constantTerm = p.anyOf(p.number, p.negative(pFraction), pFraction)

If you switch the question to solve for x, do you simply change all xs to ys and vice versa

with all the coding?

Ed