Question: Using Grid with add?

I'm trying to use the Grid package to speed up my computations somewhat, however Grid[Map] does not seem to play well with add.

Erroran := proc (e, g, f, T)
 local k, errorterm, terms, n, ma, i;

 ma := proc (n) options operator, arrow; evalf(T*(1/2)*maximize(int(f*f, x = 0 .. 1)-add(int(f*sqrt(2)*sin(k*Pi*x), x = 0 .. 1), k = 0 .. n), s = 0 .. T)/(Pi*Pi)) end proc;

 errorterm := proc (n) options operator, arrow; int(g*g, x = 0 .. 1, numeric)-add(int(g*sqrt(2)*sin(k*Pi*x), x = 0 .. 1, numeric), k = 1 .. n)+ma(n) end proc;

 i := 1;

 while e < Grid[Map](errorterm, i) do i := i+1 
end do;
 return i
 end proc

h := piecewise(x <= 0, 0, 0 < x and x < 1, 3, x >= 1, 0)

Erroran(0.1e-3, h, 1, 1)

 

When I run the above code I get the error "Error, (in Grid:-Map) unable to execute add." Does anyone know of a workaround to this? Or another way to speed up my code? If so it would be much appreciated. 

The code works perfectly well if I don't use Grid and just use "errorterm(i)" in my while loop instead.

Please Wait...