MATLAB going from Cart to Pol back to Cart coords for cylindrical plot -


1. want do:
(i) use input n generate n*n cartesian grid

[x y] = meshgrid(linspace(-1,1,n));   

(ii) generate polar coordinates

[theta r] = cart2pol(x,y);   

(iii) evaluate function in cylindrical coordinates

z = f(theta,r);   

(iv) plot result using (say) pcolor (or surf, or anything)

pcolor(x,y,abs(z).^2) %the function complex, laguerre-gauss exact.   

2. can do... way can plots work starting polar parameters , working cartesian there:
(i)
define parameters

r=linspace(0,1,n); theta=linspace(0,2*pi,n);   

(ii) create both grids , evaluate f

[theta r]=meshgrid(theta,r);   [x y]=pol2cart(theta,r);   z=f(theta,r);   

(iii) plot

pcolor(x,y,abs(z).^2)   

the problem grid circular, , evaluate function everywhere on rectangular grid (because analysis depends on having square pixel arrays). reiterate, using method 2 above, circular plot circumscribed in square; imagine black circle white along edges... want evaluate function in "white" region. however, using method 1 not work -- function messed when plot (just google laguerre-gauss modes see plots should like).

i want able start rect grid , assign every point polar coordinate, instead of start polar coordinates , assign them cartesian points.

i've been messing on off long time, , can't figure out how around seemingly simple issue.

edit 1
seems problem lies in how coordinate matrices generated. below i've posted screen-shots of simple 3by3 example illustrating how approach 1 , approach 2 generate different numbers.

how make these numbers compatible?

i have no reputation points cannot upload images directly... links below show 3by3 example... see comments links actual images of laguerre-gauss plots i'm trying make...

apply cart2pol
apply pol2cart

edit 2

currently, result of approach (1.) gives wrong results, shown here:

desired approach, wrong result

the second approach gives right images, unfortunately it's circle , not entire square. shown here:

implemented approach, limited result

3d plots of both approaches shown here - colorful part of top figure correct.

edit 3

here screenshot of function f being used above. note, asks more input parameters r,theta. typical values are:

w0 = 0.5; p = 0; l = 5; 

the function c gives normalization , l laguerre polynomials. both of these functions have been thoroughly tested , yield expected results.

edit 4
here enough code run example z=u(0,5,r,phi,w0)+u(0,-5,r,phi,w0); explicitly. plot given pcolor(x,y,abs(z).^2).

note lpl() function inserted comment. have saved own m-file u function run properly.

%% laguerre-gauss modes u = u(p,l,r,phi,w0) %  source: oam theory paper section 2.a eqn 1. %  assuming polar coordinates , evaluating @ beam waist. % -- is, z=0 w(z)=w0(sqrt(1+z/zr))  % ---- ie, w(0) = w0 % assuming z=0 renders gouy phase arctan(z/zr) irrelevant. % note: rayleigh range zr not explicitly defined because z=0 --> irrelevant too. % since zr wavelength dependent term, wavelength doesn't % matter.  function out = u(p,l,r,phi,w0) %function handles clarity e = @(x) exp(x); c = @(p,l) sqrt((2*factorial(p))/(pi*factorial(p+abs(l)))); l = @(p,l,z) lpl(p,l,z);  %% lpl() function % function out = lpl(p,l,z) %  % l=abs(l); % ll=0; % mm=1:p+1 %     m=mm-1; %     l=ll; %     ll= l+((-1)^m)*(factorial(p+l)/(factorial(p-m)*factorial(l+m)*factorial(m)))*(z.^m);  % end % out = ll;  %%   out = (c(p,l)/w0)*...     (((sqrt(2).*r)/w0)^abs(l))*...     (e((-r.^2)/w0^2))*...     (l(p,l,((2.*r.^2)/w0^2)))*...     (e((-1)*1i*l.*phi)); `` 

edit
answer rewritten based on code provided in edit 4 of question.

i think trouble stems function u. don't apply element wise operations parts of equation. if change to:

out = (c(p,l)./w0).* ...              % here it's .* instead of *     (((sqrt(2).*r)./w0).^abs(l)).* ... % here it's .* instead of *     (e((-r.^2)./w0.^2)).* ...          % here it's .* instead of *     (l(p,l,((2.*r.^2)./w0.^2))).* ...  % here it's .* instead of *     (e((-1)*1i*l.*phi)); 

you following 2 results, shown below.

this figure used input of cartesian coordinates:

enter image description here

and figure used polar coordinates:

enter image description here

the "coarser" resolution in second figure due less suitable resolution of grid. in essence resolve same features.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -