Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
numerical integration from data in cylindrical coordinates

Subject: numerical integration from data in cylindrical coordinates

From: Neal Lafferty

Date: 6 Oct, 2010 17:45:26

Message: 1 of 6

I have a 2d array of data 402 x 402 in the shape of (approximately) an airy disk that I need like to take the cumulative integral of. The data has radial symmetry, and I would like to plot the cumulative integral with respect to radius. cumtrapz only handles 1 dimension of integration at a time, and it is in cartesian coordinates.

I want to numerically integrate from the center of the data (x=0,y=0) or r=0 outward, over theta=0 to 2pi, cumulatively. Can I do this in MATLAB?

Thanks for any help that you might be able to offer.

Neal

Subject: numerical integration from data in cylindrical coordinates

From: Roger Stafford

Date: 6 Oct, 2010 20:12:20

Message: 2 of 6

"Neal Lafferty" <nxl7930@rit.edu> wrote in message <i8icjm$l55$1@fred.mathworks.com>...
> I have a 2d array of data 402 x 402 in the shape of (approximately) an airy disk that I need like to take the cumulative integral of. The data has radial symmetry, and I would like to plot the cumulative integral with respect to radius. cumtrapz only handles 1 dimension of integration at a time, and it is in cartesian coordinates.
>
> I want to numerically integrate from the center of the data (x=0,y=0) or r=0 outward, over theta=0 to 2pi, cumulatively. Can I do this in MATLAB?
>
> Thanks for any help that you might be able to offer.
>
> Neal
- - - - - - -
  You haven't made it clear what the points in your 402 x 402 array correspond to. Are they cartesian coordinates or polar coordinates? Also what quantity is being represented by the values at these array points? Are you attempting to find a double integral with respect to polar coordinates? Your mention of an Airy disk suggests that you are actually doing only a single integration. The long and short of my message is that I feel you need to rewrite your question in such a manner as to make it clear to us what you are actually asking.

Roger Stafford

Subject: numerical integration from data in cylindrical coordinates

From: Roger Stafford

Date: 6 Oct, 2010 20:33:38

Message: 3 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8il74$ro0$1@fred.mathworks.com>...
> You haven't made it clear what the points in your 402 x 402 array correspond to. Are they cartesian coordinates or polar coordinates? Also what quantity is being represented by the values at these array points? Are you attempting to find a double integral with respect to polar coordinates? Your mention of an Airy disk suggests that you are actually doing only a single integration. The long and short of my message is that I feel you need to rewrite your question in such a manner as to make it clear to us what you are actually asking.
>
> Roger Stafford
- - - - - - - - -
  I failed to read your subject title carefully. Apparently your array of points correspond to radius r and distance z cylindrical coordinates, and you are attempted to find the numerical triple integral of some quantity that is constant with respect to theta, and which would therefore require only an appropriate double integration. Is that correct?

Roger Stafford

Subject: numerical integration from data in cylindrical coordinates

From: Neal Lafferty

Date: 7 Oct, 2010 13:16:03

Message: 4 of 6

> I failed to read your subject title carefully. Apparently your array of points correspond to radius r and distance z cylindrical coordinates, and you are attempted to find the numerical triple integral of some quantity that is constant with respect to theta, and which would therefore require only an appropriate double integration. Is that correct?
>
> Roger Stafford

Roger,
  Thanks for taking a look and responding to my post. You are correct, I would like to perform a double integral (numerically) on my data. The problem is that now, using cumtrapz, I have to integrate over the columns first, and then re-run to integrate the rows. I'd like to have the data where I can take the cumulative integral over 0 to 2pi, and from r=0 to some radius.
 To better illustrate, my data resembles http://en.wikipedia.org/wiki/File:Airy-pattern.svg when plotted with imagesc.
I'd like to plot the cumulative volume under the curve with respect to radius, over 360 degrees. Graphically, it would resemble http://en.wikipedia.org/wiki/File:Airy_Pattern_Intensity_and_Encircled_Power.svg
So in short I want to numrically integrate an array that has rows/columns (cartesian) data in cylindrical coordinates. Is that possible in MATLAB?

Thanks for the responses! I hope I could clarify.

Subject: numerical integration from data in cylindrical coordinates

From: Neal Lafferty

Date: 19 Oct, 2010 02:40:05

Message: 5 of 6

I was able to solve my problem in a satisfactory way. I wanted to post it in case someone else is searching for a solution to this problem.
The data I wanted to numerically integrate was from a 402x402 matrix generated from an external program. Based on http://www.mathworks.com/support/solutions/en/data/1-1679J/index.html?solution=1-1679J , I decided to use trapz(trapz(data) to perform the double integration. However, I wanted to get the encircled volume as a function of the radius of a circle. Here is my solution:
r = linspace(0,max(x),length(x)/2); % The vector of values of r to integrate

% Pre-allocate for speed
rVolume = zeros(size(r)); % This will store the volumes for each r

% For each element in rVolume, create a filter function that is zero outside
% of the radius of interest. Then multiply the original data by the filter before
% integration. This way, the data can be easily integrated over the cylindrical
% region of interest.
for i=1:length(r)
    % Create a filter for the original data
    filter = sqrt(X.^2+Y.^2) <= r(i); % The filter is 1 inside radius, 0 outside
    % imagesc(x,y,filter);
    rVolume(i)=trapz(x,trapz(y,normData.*filter));
end

% Plot the cumulative integrated area vs radius
plot(r,rVolume);

Subject: numerical integration from data in cylindrical coordinates

From: victoriacurto1@gmail.com

Date: 29 Jan, 2014 18:25:57

Message: 6 of 6

Neal,

I know your post is quite old but I am having the same problem you encountered for calculating the cylindrical volume under a surface. I'm looking at your code but I'm not sure what you mean by normData?



On Tuesday, October 19, 2010 4:40:05 AM UTC+2, Neal Lafferty wrote:
> I was able to solve my problem in a satisfactory way. I wanted to post it in case someone else is searching for a solution to this problem.
> The data I wanted to numerically integrate was from a 402x402 matrix generated from an external program. Based on http://www.mathworks.com/support/solutions/en/data/1-1679J/index.html?solution=1-1679J , I decided to use trapz(trapz(data) to perform the double integration. However, I wanted to get the encircled volume as a function of the radius of a circle. Here is my solution:
> r = linspace(0,max(x),length(x)/2); % The vector of values of r to integrate
>
> % Pre-allocate for speed
> rVolume = zeros(size(r)); % This will store the volumes for each r
>
> % For each element in rVolume, create a filter function that is zero outside
> % of the radius of interest. Then multiply the original data by the filter before
> % integration. This way, the data can be easily integrated over the cylindrical
> % region of interest.
> for i=1:length(r)
> % Create a filter for the original data
> filter = sqrt(X.^2+Y.^2) <= r(i); % The filter is 1 inside radius, 0 outside
> % imagesc(x,y,filter);
> rVolume(i)=trapz(x,trapz(y,normData.*filter));
> end
>
> % Plot the cumulative integrated area vs radius
> plot(r,rVolume);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us