Is there a way to generate function prescription programmatically

asmarcz shared this question 2 weeks ago
Answered

I need to create long function prescriptions and plot them based on parameters.


For example for a and b I want to plot three functions abs(x-a), abs(x-b) and abs(x-a)+abs(x-b)


I don't want to enter all this by hand and generate much longer.


How can I utilize JavaScript for this?

Comments (10)

photo
1

I have read parts of the documentation however I skipped this part because I don't want to embed GeoGebra but rather use the online version.

photo
photo
1

it is clear to me what do you exactly want

set 2 sliders a,b

and manipulate one function to a,b

or def a function

f(x,a,b)

and set multiple functions

f12(x)=f(x,1,2), ....

or what else?

photo
1

This is clever I may use this however it doesn't solve my problem.

photo
photo
1

this?

Files: foro.ggb
photo
1

I was aware of sliders I need a slightly different approach.

photo
photo
1

Thank you all for suggestions. It didn't occur to me I could use GeoGebra API, without actually embedding it, to my needs in browser JavaScript console. However the solution I was looking for was to define somewhere a script that can be run inside the app itself and not externally by pasting it into browser console and executing it.


Something on the lines of (I am speculating here):


let objects = []

function routine() {
  objects.forEach(e => ggbApplet.deleteObject(e))
  for (let i = 0; i < 100; i++) {
    // generate function
    let f = `abs(x*${i})`
    objects.append(ggbApplet.evalCommandGetLabels(f))
  }
}

photo
1

Hm,

you can use GeoGebra-Script, Execute()-Commnd in an update-Event of an object

or simply some thing like

Sequence(abs(x i), i, 1, 10)

/9f+2OPLuZUf4YRUSJaLtqe7pAR1S3HV6YvKZ6CdD0eSkqQjwDRUWssBUVCygqQqoERUWsoKgoKkI8AUVFrKCoKCpCPAFFRaygqCgqQjwBRUWssL5GiUVdDPVWg78VIRcaiooQubBHESIZiooQubBHESIZiooQubBHESIZiooQubBHESIZiooQubBHESIZiooQubBHESIZiooQufwfeX96+EuFd2QAAAAASUVORK5CYII=


generates a list


Or you can update existing function by ParseToFunction( <Function>, <String> )


BTW: Javascript that can be run inside the app itself - or what do mean with "not externally by pasting it into browser console and executing it"? In this app https://www.geogebra.org/m/gwm7fbzu javascript cipher text. In this App https://www.geogebra.org/m/weyhrbrq some examples 4 GeoGebra Script...

Or

photo
1

The thing is. How is it going to be to any use inside event listener? I need to run it on my demand, it doesn't happen on update of object. I may miss a point here as I am not completely familiar with GGB.


The for loop was just a simple demo. I can't show you my logic since it isn't completed yet. However it will not be replicable by functions such as Sequence, I assume.

photo
1

I need to run it on my demand,


one button?


it is difficult to understand your query

photo
© 2019 International GeoGebra Institute