Home

Homework  Index  Syllabus


For HW #2

 

(*
Define a function f[g_, lis_], 
whose input is a function-name g and a list lis,
and does the following : 
it first computes g(x) for every element x in lis, 
then adds up all the results
*)

(* Example *)

In[6]:= g[x_] := x^2
            f[g, {1, 2, 3}] (* computes 1^2 + 2^2 + 3^2 *)

Out[7]= 14

(* Hint: use Map and Apply *)