# Integration for n-times

Hi all,

I was wondering if there is any way to do a definite integral for n times (say n=50) at different points for an input variable (here P) and put the result of each integral in a wave.

Let me explain it a little bit more.

Suppose I have a function P*x^2 that I need to integrate from x=0 to x=2 with respect to x at different values of P and put each result of the integration in a wave. P runs from 0 to 49, i.e. P=0,1,2,.......,49. So I need to do the integration 50 times for 50 different values of P.

I can run the integration once for one single value of P but to do it 50 times, is there any simple way to do it in Igor? I can't pass the number of integration as a parameter in the userfunc.

#pragma TextEncoding = "MacRoman"
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function MyN()

Make/O/N=50 x
Make/O/N=50 Y

Variable n

For (n=1; n<=50; n+=1)
x[n]=n
Variable R = Integrate1D(userfunc,0,2,0)
Y[n]=R
Printf "%.10f\r" R
endfor

End

Function userFunc(v)
Variable v

return 1*v^2  //Integrating function Y = P*x^2, in this case P =
End
`Integrate1D(userfunc,0,2,0)`

Thanks,

Ann

I must be missing something. In this case, for each P value the integral is simply P * Integral of 1*v^2 for v 0..2. No need to do integration 50x, just once.

I think that you're asking how to make a wave assignment with Integrate1D where some parameter to be used in the integration function is taken from the wave.

Because the only way to supply extra parameters to integrate1D is as a parameter wave, you need a 'wrapper' function, something like this:

function WrappperForIntegrate1D(variable var)
make /free pwave={var}
return Integrate1D(UserFunctionName, 0, 2, 2, 0, pwave)
end

then, in your example, you can use a wave assignment like

`y = WrappperForIntegrate1D(p)`

Using x, y and r as names for waves and variables is a bad idea, each if these has a special meaning in Igor.

Also execute

```DisplayHelpTopic "Waveform Arithmetic and Assignment"
```

Thank you all for your suggestions. Now I have figured out the solution to it.

Ann