# Managing variable situation (complex conditional scripting?)

ilic.ferretti shared this question 3 years ago

Hi to all,

I'm developing some materials about functions and limits

I would like to build an interactive animation which given a [continuous] function and selecting an x_0 value, could show

1. the corresponding limit i.e. as the function is continuous, the output f(x_0)
2. an interval on the y axis describing the selected proximity to the limit i.e f(x_0)-e<y<f(x_0)+e
3. the corresponding interval on x-axis, which guarantees that x values taken inside it will give an output which is inside the selected range on y axis,

At present moment I managed to get to point 2 (see attached example)

My problem is to find a command or a sequence of commands which can choose the correct intercepts between the function and the two lines corresponding to the extremes of the range on y axis. given the correct intercepts, I could the project them on x-axis and get the desired range on x values.

I would need to choose the two points whose x is nearest to x_0, but I cannot understand whether it is possible to find them using geogebrascript commands, that is with pure sequential programming and without iterations or complex if/then combinations. I gave a look to javascript support but it doesn't look simple either.

Any help or suggestion (or the confirmation that my goal is not reachable) is welcome

Ilic

2

Maybe something like this?

`Sort(Join({Intersect(f,y=f(x_0) - e )},{Intersect(f,y=f(x_0) + e )}))`

1

Thank you so much for your suggestion, it made me study a little bit deeper the usage of lists and their commands.

I guess that what I need would be something like (pseudo-code)

```P=(x_0, f(x_0))
L1 = Sort(Join({Intersect(f,y=f(x_0) - e )}, {P}, {Intersect(f,y=f(x_0) + e )}))
x_{min} = L1[IndexOf(L1, P)-1].x
x_{max} = L1[IndexOf(L1, P)+1].x```
or something like that.

I haven't checked yet a similar approach (and thus I do not now whether a function like IndexOf() is available or not) because meanwhile I focused on building manual tools which should allow students to build their own interval and play with them, hopefully making them understand better the underlying ideas.

I'm sharing here what I've done, as an alternative solution to my original problem. A rough example of such tool is available here (sorry, in Italian)

Find attached the .ggt file with the tools.

As soon as I'll have the time to check the way you suggested, Micheal, I'll update this thread.

Meanwhile thank you again very much!