Stopping an iteration when values get close together?

Alasdair shared this question 6 months ago
Needs Answer

I'm doing a little numerical work, and I can create an iteration and run it, either in the spreadsheet view or else with IterationList. However, I'd like to run it until consecutive values reach a certain closeness (or after a fixed number of iterations, whichever comes first).

Thus a command something like

IterationsUntil(f, x0, n, eps)

will run an iteration x <- f(x) until either n steps, or until two consecutive values differ in absolute value by eps. It could be used as

IterationsUntil(cos(x),0.5,100.1E-10)

Does this mean writing a Custom Tool using JavaScript, or is there an easier way?

Thanks!

Comments (2)

photo
1

Please post your .ggb file

photo
1

Thank you - but I don't have a ggb file yet - I'm not up to that stage! I was hoping for some pointers to information which would enable me to write such a function myself. I have done some JavaScript programming, so that doesn't worry me. If there is any documentation about adding your own JavaScript function to GeoGebra, I'd love to know of it!

photo
© 2020 International GeoGebra Institute