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
Function
, you don't needSetDelayed (:=)
; instead,Set (=)
should be used. i.e.g2 = ...
would be sufficient (and efficient too, becausef2
andg2
are evaluated only once) $\endgroup$ – JungHwan Min Nov 5 '16 at 4:53