Can simpleFunction use predefined variables

Say I have this code:

A = 1
B = 2
C = 3
e = simpleFunction("A+B+C+x", "x")
# Would 'e' equal 6+x or nothing?
# Also I was wondering if I should do:
# e = simpleFunction("${A}+${B}+${C}+x", "x")

Yes to your second version of e. The first would not evaluate.

In general, the “x” argument is unnecessary because simpleFunction() defaults in terms of x. The variable arguments are only required if it is a variable other than x or there are more than one independent variable.

Seems like “e” works in CL, but if you move it to a graph as a function. It will make “e” the constant 2.71828182846… instead of the function.

Thanks! Also I did forget that simpleFunction is default to variables x and y.

For @SteinSchreiber’s response, yes you are correct, but I was just making a quick example variable to ask the question

1 Like

Actually, don’t think of it in terms of x and y. It’s any function or isolated variable defined in terms of x.

So, all of these as input entries…

3x+5
y=3x+5
f(x)=3x+5
d=3x+5
m=3x+5
h(x)=3x+5

… would be valid and evaluable for this:

myFunction = simpleFunction(this.latex)

I think “e” just happened to be the name chosen for the function and the question was about how to write the expression for the simpleFunction(), not about how the character e is evaluated.

2 Likes

But how would CL “find” the h in:

h(x)=3x+5?

What do you mean by “find”? It’s just function notation. It doesn’t work if it’s on the right hand side. For example, the following is invalid and can’t be evaluated with the same simpleFunction(this.latex):

3x+5=h(x)

Basically, if you could write the function in the calculator (in terms of x) then it’ll work for simpleFunction(). Your function names can even have subscripts:

m_{yFunction}(x)=3x+5

Ah yes. Your second part answered my question. What I meant by “find” was how CL would know that h is a user-defined function, not just another variable that is being multiplied by x (Since some people write multiplication as a(b)).

Function notation takes precedence over multiplication… on the left hand side of an equation.

Okay I didn’t know that. Pretty cool! Again.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.