# Changing Variables, Limiting the domain, and checking

I’ve asked something similar before, but now I’m wanting to take things a step further and I’m stuck. I would like to graph C=45h+85 {0<=h<=5} and check it.

How do I get the {0<=h<=5} into my code in the math input box?

As always, many thanks for any help.
Ingrid

To clarify, you want to check if Ss entered the domain restriction correctly?

Yes. I want there to be a tick in the box when they type in C=45h+85 {0<=h<=5}

At the moment, I can only get a check mark when they type C=45h+85

Thanks

You could define a function in your input similar to what you did in the graph:

``````f= simpleFunction(parseEquation(this.latex).rhs,"h")
``````

Then, check outside of the domain to verify it’s undefined:

``````undef= isUndefined(f.evaluateAt(-0.1)) and isUndefined(f.evaluateAt(5.1))
``````

Hi Daniel

Thanks for this. But I’m not sure how I actually enter that into the input. I can copy and paste, which I’ve just tried to do, and tried a few combinations, but I keep getting a cross in the box. I’m just not quite sure how it all works together yet.

Help!

When you say “input”, do you mean how do you type it into the Math Input box - ie:

or do you mean how do you put it into the CL code so that it checks it correctly?

EDIT: Ignore that, sorry - I’ve just tested it with Daniel’s suggestions and yes, it does still give the cross. It seems to fail the pattern matching as soon as you include a domain restriction…

Yes, that’s the problem!

I want to press submit with exactly what you have on your screen and have it come up with a check mark.

Sorry to have been so unclear.

``````f= simpleFunction(parseEquation(this.latex).rhs,"h")
undef= isUndefined(f.evaluateAt(-0.1)) and isUndefined(f.evaluateAt(5.1))
``````

I think on this occasion you’ll need to evaluate the function for correctness rather than using pattern matching - so this works, for example:

``````
f= simpleFunction(parseEquation(this.latex).rhs,"h")

correct: check
check=f.evaluateAt(1)=130 and f.evaluateAt(2)=175
undef= isUndefined(f.evaluateAt(-0.1)) and isUndefined(f.evaluateAt(5.1))

suffix: when not(this.submitted) ""
when check and undef "✅"
otherwise "❌"
``````

It does not stop students entering wacky variations that evaluate to the same - eg. C=(90/2)h+85 {…} or C=30h+15h+40+45 {…} - but at least works with the domain restriction, where pattern matching seems to trip up…

Thank you both for your suggestions. Very much appreciated. It works now.

Originally I thought I had to do the pattern matching thing in order to enter an equation with variables other than x and y. So is that not the case, so long as I have the function defined in terms of, say, h, as I have in the graph?

Many thanks
Ingrid

For

``````f= simpleFunction(parseEquation(this.latex).rhs,"h")
``````

The “h” at the end defines what the function is in terms of, so when you evaluateAt that is the variable being evaluated. You can even do multiple say for a volume formula by simply adding more parameters.

``````V=simpleFunction(`LWH`,"L","W","H")
``````

Then, evaluate as needed:

``````prism= V.evaluateAt(4,5,6)
``````

That’s brilliant, thanks!