# Simple "Apply" function

This is such a simple question its almost embarrassing, and I'm surprised I haven't figured out where I'm going wrong with this..Probably because I'm really new to the commands Function and Apply and I might be using them wrong. But anyways, here it goes:

Input:

Clear[g2, x];
g2 := Function[x, Apply[Log[1 + x^2] + 6 x + x^3,x]]
g2[{2, 3}]


Output:

{20 + Log[5], 45 + Log[10]}[2, 3]


I have the answer but whats going on with the [2,3]?? I thought I need the extra "x" because Apply takes 2 arguments..

Here is an example I am trying to follow:

Input:

Clear[f2];
f2 := Function[pt, Sqrt[Apply[Plus, pt^2]]]
f2[{3, 4, 12}]


Output:

13

• Slightly off-topic, if you set a Function, you don't need SetDelayed (:=); instead, Set (=) should be used. i.e. g2 = ... would be sufficient (and efficient too, because f2 and g2 are evaluated only once) Nov 5, 2016 at 4:53

It is not clear what you are trying to do. The example you are trying to follow is not similar to your function g2. Since all of the functions used in g2 are Listable there is no need to use Apply

Clear[g2, x];
g2 := Function[x, Log[1 + x^2] + 6 x + x^3]
g2[{2, 3}]

(*  {20 + Log[5], 45 + Log[10]}  *)

Log[1 + #^2] + 6 # + #^3 &[{2, 3}]

(*  {20 + Log[5], 45 + Log[10]}  *)


If the components of g2 weren't Listable you could use Map

Log[1 + #^2] + 6 # + #^3 & /@ {2, 3}

(*  {20 + Log[5], 45 + Log[10]}  *)


Showing that they are all equivalent

% == %% == %%%

(*  True  *)

• Sorry for the unclear question. Thanks for your clarification because I was obviously using Apply in an inappropriate way Nov 5, 2016 at 4:05