User created vector (or list) function?

Alasdair shared this question 2 years ago
Answered

I would like to create a function which takes a list as input and returns a list as output, something like

shift(x) = Flatten(Append(take(x,2),first(x)))

which is supposed to shift the first element to the last place. (This is just an example). The idea was that I'd then iterate this function using IterationList.

I've tried using both the Algebra and CAS views, and they both give me errors. I know I could probably do what I wanted with the spreadsheet, but I would much prefer to use a function, such as above.

Can this be done? Thanks!

Comments (9)

photo
1

983f102bb7088f5901c70837084dc0b6

You have to define user-functions with „keep input“ in CAS

II don’t know how to do this in algebra view?

photo
1

Thank you! I can see how that is meant to work. I'm also trying to apply it to some matrix functions, for example, in the CAS view:

40ba4a03334b5c9fb0afbfd056ff647e

but as you see all I get is a question mark. I would love to be able to write a matrix-valued function, using the Keep Input Tool (or any other way), but I can't get it to work. I had already previously defined the matrices D and a. Do I have to explicitly define my function mm to return a matrix? How can I get my function to work? Again, many thanks!

photo
1

Thank you! I can see how that is meant to work. I'm also trying to apply it to some matrix functions, for example, in the CAS view (which I attach as an image) but as you see all I get is a question mark. I would love to be able to write a matrix-valued function, using the Keep Input Tool (or any other way), but I can't get it to work. I had already previously defined the matrices D and a. Do I have to explicitly define my function mm to return a matrix? How can I get my function to work? Again, many thanks!

photo
1

I used to add a take around user-matrix-functions to make it work


see https://www.geogebra.org/m/c6Q7gDmC

Line 1 - if this is your question?


more examples to user-matrix-functions


https://www.geogebra.org/m/j3fqtfcn, https://www.geogebra.org/m/bk6g7h62 (line 2)

photo
1

Many thanks again! - yes, the use of Take seems to work. I am in fact trying to write the Jacobi and Gauss-Seidel iterations, for my students to play with. I've almost got it, the combination of Take and the use of Keep Input Tool proves me now with a usable function. However, I can't iterate it. I've defined a function "jc" which does one Jacobi iteration; it takes a 3x1 matrix as input and returns another 3x1 matrix as output. And it can be nested: "jc(jc(jc(v))) " works fine.

But it won't work with Iteration. I thought that "Iteration(jc,v,3)" would produce exactly the same output as my nested functions... but it produces a horrible mess of nested matrices:

7bd185ddaf7a4aa810fcc962c9f57ed4


This is one of the things I find really annoying about GeoGebra: that its function behaviour is never quite as straightforward as you'd like. And it doesn"t really have a proper programming interface: the scripting and tools is more complicated than it needs to be.

Anyway, thank you again for your help and for the links to your remarkable and lovely 3D GeoGebra uploads, and I'll keep fiddling away.

photo
1

Programing is really very special in ggb. Do know SMath a Mathcad clone with a paperlike Interface - very interesting?

If you will provide the file I will have a glance about it

Some thiing like

https://www.geogebra.org/m/zzjzgzwt

photo
1

Thank you very much - in the end I had to ditch GeoGebra (at least for this topic) and use Excel exclusively. In fact, I'm really regretting choosing GeoGebra at all for this course, which is a basic introduction to numerical methods. GeoGebra can draw some pretty pictures, but as a software product it's very flaky and fragile; keeps crashing and losing all my work, doesn't even seem to have a decent cut-and-paste mechanism, and no real programming. I'm running this course again in a few months, and I'll choose something else. I think the trouble with GeoGebra is that everything is built from a dynamics graphics perspective, which is simply too inflexible for almost everything else. The CAS part has apparently been ported into GeoGebra from XCas/Giac, so I simply might use this instead next time. It has proper programming including loops and branches, proper handling of variables, and seems in every way a more robust and mathematically sophisticated product.

But many thanks for your kind and generous comments, and for your help!

photo
photo
1

yo habitualmente cuando quiero funciones que GG no tiene de forma interna suelo crear una herramienta personal que simule una función, por ejemplo creo a, defino D*a con D escrita termino a termino en la instruccion y una heramienta mm con entradas , a y salida D*a entonces con escribir por ejemplo mm(b) simulo mm(x) para x=b. el efecto es muy parecido puesto que mm no tiene representacion

Files: foro.ggb
photo
1

Thank you again (and thank you also to Google translate!) What this means, in effect, that you use one paradigm for pretty much every other system out there: Matlab, GNU Octave, Scilab, Maple, Mathematica, Python, Julia, SageMath, GNU Maxima, Axiom/FriCAS etc - and I've written extensively in all of these, including a few books - and a new paradigm for creating functions in GeoGebra! As far as I'm concerned, writing a function should just be a matter of coding it up in a text editor, and then loading it into the system. GeoGebra is basically not designed to be extensible, except for very simple functions and tools. Anyway, I'll struggle with it for the next few weeks...

photo
© 2023 International GeoGebra Institute