Graph labels with expression evaluation

Dynamic labels are quite useful, but I’d like to evaluate expressions and have them incorporated into labels. I find myself creating a variable just to display simple expressions (n-x). Is there any sort of “eval” syntax?

Thanks!

The only shortcut I have found is for situations where n can be a list of values. When plotting a list of points, the label list displays nicely at the corresponding points. Graphing Calculator

1 Like

If you’re using the CL, your dynamic labels can include other variable information; you just need to surround it with ${ }. For example, you can use variables created in the CL from pretty much any component (though I’d define one in the current CL for readability), or values in the graph. As to evaluating expressions, you can create functions in CL, which you can evaluate, or for simpler calculations numericValue:

n=8
x1=this.number(`x_1`)
diff=numericValue(`${n}-${x1}`)
pointLabel(`P`): "Your value is ${ diff }."
#This should read the same as P
pointLabel(`P_2`); "Your value is ${ numericValue(`${n}-${x1}`) }."

f=simpleFunction(`n-x`,"n","x")
diff2=f.evaluateAt(n,x1)
pointLabel(`Q`): "This difference is ${ diff2}."

Within the graph you can use the ${ } notation for numeric variables in the label like this.

1 Like

Thanks. I use lists that way already, but I didn’t know backticks gave math formatting. It sounds familiar … but it will be useful.

Hehe. I misunderstood your intent I suppose. Are you not wanting to display all at once as @sergeballif 's example? You can use some indexing like this, and change slider a. Takes an extra variable (which I think you were trying to avoid), but works out.

Thanks. I understand CL can compute in ways the graph cannot, but I’d like my graph code to be as simple as possible too.

Calculations are usually much cleaner in the graph, and just resort to the CL for those things the graph absolutely can’t do (or to avoid sending information back and forth between CL and graph repeatedly as it can apparently slow things down).