Q: Specify default function, when input undefined

Dear Desmos folks,

I’m trying to have a graph which shows what the student enters into a math box, but which doesn’t go completely blank when the mathbox entry is half-typed and hence undefined.

I’ve trying variations of the CL below, but none of them seem to work:

function(“f”):
when isUndefined(“f”) simpleFunction(“y=x”)
otherwise simpleFunction(input1.latex)

I think I’m not giving simpleFunction the correct input. Some other inputs that don’t work: x with backticks around it, “x” with quotes around it. In all cases, the function f simply disappears when the input box is half-formed, rather than defaulting to showing an actual line rather than just an empty graph.

Any help greatly appreciated,

Raj

f can’t really be defined in terms of itself, so you want to apply isUndefined to the LaTeX instead. To avoid repetition, I’d go with something like:

input=input1.latex
function(`f`): 
when isUndefined(input) simpleFunction("x") 
otherwise simpleFunction(input)

Thanks for the suggestion!

You raise a very valid point about making sure that the definition of f doesn’t mention itself. That said, the solution that you posted doesn’t work for me. Here is a minimal example:

It starts off with a malformed input, saying “x^2 +”, and the graph is blank, despite the attempt to provide a default function of x. Nothing shows up until you type something after the + sign, e.g. x^2 + 1

Raj

Apologies, I made an error in the code I gave you. It should have said:

input=simpleFunction(input1.latex)

function(`f`): when isUndefined(input) simpleFunction("x") otherwise input

(You could also just replace input with simpleFunction(input) in the original code, but I like to get into the habit of using variables for anything I am going to use more than once).

Thanks! Your change of wrapping simpleFunction around the input1.latex part fixed it for me.

Thanks again for all your help,

Raj