function y = MyErf(x)
% x is a column n-vector
% y is a column n-vector with the property that y(i) = erf(x(i)), i=1:n

% if c(k) = (-1)^k/(k!(2k+1) then 
%            c(0) = 1 
%            c(k+1) =-c(k)*(2k+1)/((k+1)(2k+3))

% Initializations...
x2 = x.^2;
k = 0;
term = x;
y = term;
next_term = -(((2*k+1)/((k+1)*(2*k+3)))*x2).*term;
next_y = y + next_term;
% Iterate as long next_y is different than y...
while max(abs(next_y - y))>0 
    y = next_y;
    term = next_term;
    k = k+1;
    next_term = -(((2*k+1)/((k+1)*(2*k+3)))*x2).*term;
    next_y = y + next_term;
end
y = y*(2/sqrt(pi));

% Partial Credit
% Correct expression inside the loop: 3 points.
% Correct termination criteria: 1 point.
% (The result is correct only if both expression and termination are correct.)
% Vectorization: 1 points.
    
    