Evaluate a function in a grid

5 ビュー (過去 30 日間)
Pablo
Pablo 2013 年 4 月 23 日
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

回答 (1 件)

Jonathan Epperl
Jonathan Epperl 2013 年 4 月 24 日
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.
  1 件のコメント
Pablo
Pablo 2013 年 4 月 24 日
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
thanks for your comment,
Pablo

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by