# Evaluate a function in a grid

12 views (last 30 days)
Pablo on 23 Apr 2013
I want to plot an isosurface of a function*_ v_*.
Problem is that v doesn't accept matrix arguments (not vectorizable function as it contains Laguerre associated polynomials)
So if I create a meshgrid for the values of x,y,l
[r,th,l]=meshgrid(0:0.5:5,0:pi/2:2*pi,0:2);
x=r.*cos(th);
y=r.*sin(th);
Then I suppose to evaluate v using loops (counters) as I can not bypass x , y & l as arguments
But I'm doing something wrong, and as a consequence I'm not evaluating v in the points of the grid:
for l=0:2
k=k+1;
for r=0:0.5:5
i=i+1;
for th=0:pi/2:2*pi
j=j+1;
fun1=@(R)4*real(exp(-r.^2-R^2+2*1i*R*l./r).*(r+1i*R).^(2*l).*...
(mfun('L',n/2-l/2,l,r.^2+R^2)).^2);
v(i,j,k)=integral(fun1,-inf,inf);
end
end
end
does someone knows how to do the loops so I can obtain a v that matches in size with x, y, l so I can use:
isosurface(x,y,l,v) ??
or does someone knows how to obtain the mentioned isosurface v through an alternative way?
I actually need all the help I can get to do this.
Thanks, Pablo

Jonathan Epperl on 24 Apr 2013
Does that code run for you? I'm sure it doesn't, you should have mentioned that, along with the error messages...
Anyway, there are several problems:
• integral needs the option 'ArrayValued',true to integrate vector valued functions.
• the term 1./r in your fun1 evaluates to [Inf ...]
• you redefine l (terrible choice of a variable name btw) as your loop variable, so by the time the loop is done (once you fixed it), l will have the value 2, and not be a 3-dim array.
Fix that, see if it works, if it doesn't come back here, this time with error messages, please.
Pablo on 24 Apr 2013
No well, when you try to evaluate isosurface(x,y,l,v) it returns you the message error
Error using isosurface (line 74)
The size of X must match the size of V or the number of columns of V.
Error in proyecto3 (line 29)
fv = isosurface(x,y,z,v,0.5);
They just would have the same dimension if counters i and j didn't change during the loops that change the value of variables r and l(sorry for the name)
then, I don't know exactly how to do