2.38 evaluate \(f(x)\) on a vector of values

Given a function \(f(x)\) evaluate it for each value contained in a vector. For example, given \(f(x)=x^2\) evaluate it on \((1,2,3)\) such that the result is \((1,4,9)\).

Mathematica

Clear[f,x] 
f[x_]:=x^2 
v={1,2,3}; 
f[v]
 

{1,4,9}
 

 

Matlab

clear all; 
v=[1 2 3] 
f=@(x) x.^2 
f(v)
 

ans = 
     1     4     9
 

 

Maple

map(x->x^2,[1,2,3])
 

[1, 4, 9]