How to make a function, on Desmos, that, if h(x) is over n, then h(x) = f(x), but if h(x) is below n, then h(x)=g(x)

desmosgraphing-functionspiecewise-continuity

I'm trying to represent on Desmos what my C++ Vex robotics flywheel control code would do, so that I can close in on an optimal constant in the equation without testing it on the robot, because that is 10s of x more time consuming, and imprecise. I have three equations:
desmos attempt
The bottom one is obviously incorrect but I am including it because it explains more concisely than words could what I want the function to be. The image below also shows what I know the graph of the speed control would look like, oscillation down towards minimal error, a threshold at which I would tell it to give up oscillating and just put in the end voltage; I didn't include that here because I didn't want more of a struggle with Desmos.

The result should look like this (ignore the values and scale)

If you know an answer that uses another software besides Desmos, that's fine with me, I just use Desmos because it's what I know and it generally works great for me.
I'm basically asking what is the syntax for representing this with a graphing software; I could write it in C++ code, but then I wouldn't see what it looks like, and seeing it greatly helps me find solutions faster.

In the desmos image, b is the initial velocity at the first check, since the flywheel will be stimulated before the first check. v is the desired velocity of the flywheel. I also found this equation:comparator which returns 0 if x>n; 1 if x<=n. This might help with the conditional function I'm looking for. Thank you.

Best Answer

I'll preface this by stating that I'm not entirely sure if I understand what kind of function you are trying to achieve.

Some points I noticed:

  • It appears that this function can only be iteratively defined, which puts it out of scope for graphing on Desmos. (see point 3)
  • Does your function $h$ take into account that there is a critical $n$ value (define this to be $n_0:=e^{1/e}$). Where $g(x) < f(x)$ for all $x>n_0$. However, no such inequality holds on $0<x\leq n_0$ because you can get intervals in $\mathbb{R}$ such that $g(x)\geq f(x)$.
  • The example you've provided at the bottom of the question $I(x,n)$ behaves like an indicator on the x-inputs of $I$. Whereas the question in the title is concerned with some indicator behavior conditioned on the outputs of $h$ (ie. they are describing two different things)

I think that the path of least resistance for you would be to code the function in C++ and output its values to a .csv file and then plot that.