How to apply a multi-variable function to the elements of a list

hbghlyj shared this question 2 months ago
Answered

I have function f with n arguments and a list L with n elements. How can I apply f to the elements of L?

For example, we have the function

Conic( <Point>, <Point>, <Point>, <Point>, <Point> )
and a list

L={(0,0),(0,1),(1,0),(3,6),(6,3)}
I have to write

Conic(Element(L,1),Element(L,2),Element(L,3),Element(L,4),Element(L,5))

to get the conic through the five points so that the conic will update when L is changed.

However it takes a lot of time to write Element(L,1) ... Element(L,5)

How can I do it in a simpler way?

Comments (6)

photo
1

better if you begin with 5 points and create conic(A,B,C,D,E) . if you want also the set type {A,B,C,D,E} in new input

or you can type conic(L(1),L(2),L(3),L(4),L(5))

photo
1

Thanks. It works fine.

And I hope geogebra will have a function similar to Apply in Mathematica to directly get rid of a level of lists.

In Mathematica, Apply[f, {a, b, c, d}] or f@@{a,b,c,d} are the same as f[a, b, c, d].

f @@ {{a, b}, {c}, d} is the same as f[{a, b}, {c}, d]

photo
photo
2

Yes, there's a shortcut for this command. Try simply

Conic(L)

photo
1

I am afraid that it returns Undefined in version 5.0.

f4210896e824891f1af01d3c75fc8bfc

photo
1

comprobado conic() does not work with lists. classic 5 nor 6

photo
1

Sorry, it's for a list of (6) numbers, not points. My mistake

photo
© 2021 International GeoGebra Institute