I know there’s parseEquation
, parseInequality
and parseOrderedPair
, but how do I go about making a piecewise equation? There isn’t an equation parser for that, or is there?
Here is an example (I think it’s what you mean…)
Thanks a lot (again)!
I will check it out later because as you can tell its pretty late at my location.
After looking at it, it wasn’t exactly what I wanted. I wanted something like the Desmos piecewise equation, like a=1
and then {a=1:1,0}
and then a variable would store the output (1 or 0).
Even though it wasn’t what I was looking for, I still have some questions:
What’s the purpose of .evaluateAt(this.numericValue)
in your CL code?
Also, what’s this: input.script.val
?
It actually is the Desmos piecewise equation, but you do need to make it a simpleFunction so you can plug in values to a. I added a second screen to show you what I mean. A good general tip is that you can write any expression in Desmos, copy it, and then paste to CL and you will get correctly formatted LaTex. In this case, you need \left{ instead of just {.
.evaluateAt() is a method of simpleFunction which just means you plug in a numeric value and it returns the function at that value. So:
f = simpleFunction(x+1
, x
)
ans = f.evaluateAt(5)
ans would be 6.
“this” is a keyword to represent the current CL component you are in, so you can access its sources. So this.numericValue inside a math input returns the numeric value of whatever the user entered.
so altogether, f.evaluateAt(this.numericValue) would plug the entered value into the defined function.
To access the variables inside a different component, you start with the name you gave the component, then .script, which will access any variables you have established in that component. You have to pay attention to component names because of this. If you call another component by name, it will first look for it inside the screen you are in. But if it is not there, it will look for it in another screen. If it only exists in one screen, then you are fine, but if a component with the same name exists in more than one screen, you get a naming collision.
For example, if screen 1, 2, and 3 all have a component called “input” and you are in another component in screen 3, if you do input.whatever it will use the input on screen 3. But if there was not input on screen 3, then you would have an error because it doesn’t know if you mean screen 1 or 2.
Oh! So .script
specifies what screen it’s in?
Okay, I didn’t know that you needed simpleFunction
to do assignment… can you just add that to my code please?
I’m pretty aware of evalutateAt
, and I know that simpleFunction
can be used like simpleFunction("2x+y", "x", "y")
(or something close to that), but not for piecewise equations.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.