Does anyone know how to do an integration for a known function in igor

Dear All,

I have a function which is given by:

Y=I(Q)Q^2

and

X=Q

Integrating Y, Int[ I(Q)Q^2 ]dQ, actually gives the area under this curve Y (attached).



Does anyone know how to do an integrate this curve for a given range from X_min to X_max?

Thanks!
So you need to integrate the shown curve in a certain range? Then areaxy is what you are looking for. Or Integrate for more control.
Or do you want to integrate an analytic function? Then go for Integrate1D.
Create a duplicate of your waves from X_min to X_max using the Duplication operation or dialog.
Then in the Integrate dialog in the Analysis menu, choose these subset x and y waves.

If you want just the value of the area under the curve, use the areaxy function, which takes an xmin,xmax range.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Thanks

But I followed what's shown in the command help file for the areaXY function. It's still not working.

The wave names for the Xwave and Ywave are correct (attached).
untitled2.JPG (134.82 KB)
Take out the square brackets from the areaXY command so that it reads AreaXY(wave0, wave1, 43.7343, 45.3866)

Square brackets in any function format indicates the parameters are optional. If you didn't include those parameters in your function i.e. just AreaXY(wave0, wave1) it will integrate over the entire wave.

Tom
Thomas.Dane wrote:
Take out the square brackets from the areaXY command so that it reads AreaXY(wave0, wave1, 43.7343, 45.3866)

Square brackets in any function format indicates the parameters are optional. If you didn't include those parameters in your function i.e. just AreaXY(wave0, wave1) it will integrate over the entire wave.

Tom


Thanks Tom!

I'll try again.
Thomas.Dane wrote:
Take out the square brackets from the areaXY command so that it reads AreaXY(wave0, wave1, 43.7343, 45.3866)

Square brackets in any function format indicates the parameters are optional. If you didn't include those parameters in your function i.e. just AreaXY(wave0, wave1) it will integrate over the entire wave.

Tom


Still has the same problem (attached). It doesn't recognise this command somehow.

untitled_2.JPG (90.14 KB) untitled_2.JPG (90.14 KB) untitled_2.JPG (90.14 KB)
The same goes for AreaXY, i.e. use print AreaXY(wave0, wave1) in the command line. The areaxy function gives back a number, with which you would have to do something (i.e. assign to a variable in a user function).

So make sure you use only commands which work in the command line, not commands which need to be in a procedure or handled otherwise. I think the wording in the help is as follows: commands called 'operation' are useable in the command line and commands called 'function' are not (see description in the help browser). So 'print' is a operation which can be executed in the command line (and will handle the result from the area function, which does not work alone).
Yes, confusing error message, isn't it? You can't invoke a built-in function without using the return value somehow. You have to use it in an expression, assign it to a variable or print it. In 6.3 we've improved the error message, as shown in the attached screen shot.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
messagescreenshot.png (19.53 KB)
How come the area under the entire spectra is smaller than the summed area of individual peaks? (attached)

The area of the entire spectra is 467814

And that of those 6 peaks (from left to right)are as follow:

288294
67254
129156
28109
101026
27632

So, if 467814 subtracts the sum of those peaks, gives a negative value??

It can't be correct!
Print Area Problem.jpg (77.76 KB)
By the area of the individual peaks you mean that you fitted all these Gaussians and look at their area output, correct?
I guess then you can't compare with the overall area given by areaxy. Those fitted peaks are largely overlapping, especially in the tail region. From the information provided, it is a bit hard to tell what you want to achieve and what you have used so far. But I suppose these peaks are not fitted with the multipeakfit package (which are the way to go with this spectrum, I think). Go to Analysis -> Packages -> Multipeak Fitting to use it (there is a help provided in the menu).
Igor_user wrote:
How come the area under the entire spectra is smaller than the summed area of individual peaks?



I would expect it to be different. Look at the figure it seems that the fitted peaks describe only a small part of the spectrum, and e.g. much of the non-zero 'background' or 'offset' is not included in the fits. This will be included in the direct integration.

It's also hard to tell from this figure if the fitted peaks describe the data well, which would be a prerequisite.
The left endpoint of your spectrum appears to be less than zero. If you are calculating the area of the entire curve, points below zero will reduce the total area. However, from the looks of your curve, this shouldn't cause the total area to be less than the area just of the peaks.... unless the peak area is taken from y=0 rather than the baseline joining the apparent endpoints of the peaks.

As a test, I would suggest calculating areaxy for just one peak over the same limits as the fitted curve for that same peak. This may help illuminate the situation.
Did you fit the peaks individually? That is, did you use CurveFit or the Curve Fit dialog to fit little pieces of the data set? If so, the substantial overlap would mean that summing the peaks counts some of the area twice.

For overlapping peaks, I recommend the Multipeak Fit 2 package. Take a look at the demo: File->Example Experiments->Curve Fitting Multipeak Fit 2 Demo.pxp.

If you still can't figure it out, send me a copy of your Igor experiment file to support@wavemetrics.com.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
chozo wrote:
Those fitted peaks are largely overlapping, especially in the tail region.

But I suppose these peaks are not fitted with the multipeakfit package (which are the way to go with this spectrum, I think).


Dear chozo

When I fit each of these peaks, I defined a fit range in x such that the area should only be under the peak and between, say x_1, x_2.

Where x_1 and x_2 refer to the point numbers in the x wave.

And, I used the multipeakfit package.
jtigor wrote:
If you are calculating the area of the entire curve, points below zero will reduce the total area.


When calculating the area under a peak, is it possible to define a baseline joining the end points of the peak and such that the area is calculated between the peak and the baseline rather than between the peak and y=0?

If not, I'd probably have to plot each peak on a separate graph and subtract its y data by the end point value in y.
Igor_user wrote:

When calculating the area under a peak, is it possible to define a baseline joining the end points of the peak and such that the area is calculated between the peak and the baseline rather than between the peak and y=0?

If not, I'd probably have to plot each peak on a separate graph and subtract its y data by the end point value in y.


Look here http://www.igorexchange.com/project/Packages/category/55 for baseline packages. They can be used to fit a baseline under your data. Remove that baseline, then redo the peak fitting and area calculations. Or, remove the baseline from the fitted curve and then calculate the area.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
MultipeakFit2 reports the total area under a given peak from -inf to inf.

The peak functions have no vertical offset term. If the data have a baseline (like yours does) you need to include a baseline function in the fit.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
chozo wrote:
So you need to integrate the shown curve in a certain range? Then areaxy is what you are looking for. Or Integrate for more control.
Or do you want to integrate an analytic function? Then go for Integrate1D.


I used the 'Analysis' 'Integrate...'

but it returns these messages

Integrate wave0/D=wave0_INT
Integrate wave3/D=wave3_INT

Shouldn't the 'Integrate...' function give the area below this curve?
Igor_user wrote:


Shouldn't the 'Integrate...' function give the area below this curve?


No. It gives the integrated waveform. If you use differentiate you get the derivative of the waveform at each point. Integrate is the reverse.
andyfaff wrote:
Igor_user wrote:


Shouldn't the 'Integrate...' function give the area below this curve?


No. It gives the integrated waveform. If you use differentiate you get the derivative of the waveform at each point. Integrate is the reverse.

Right- and if you make a graph of wave0_INT or wave3_INT you will see that. The last point of each of those waves should be roughly equal to the result given by Area(). The fact that you got two _INT waves suggests you selected both waves as Y waves; the waveform analog of AreaXY() would be to select one wave in the Y list and the other in the X list.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com