Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.idl-pvwave

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2012, 06:51 PM
Maryam
Guest
 
Posts: n/a
Default Array Integration

Hello.

I am trying to perform a numerical integration in IDL where one of my variables is an array. Here is what I wrote:

pro ind_intg

delta=1.0
W=[0.0212330,0.0424661,0.127398,0.212330,0.297263,0.4 24661,0.530826,0.636991,0.743157,0.849322,0.955487 ,1.06165,1.16782,1.27398]
num_elements=14
A = fltarr(num_elements)
for i = 0, num_elements-1 do begin
A(i) = qpint1d('((2.*!pi*deltan^4) * x * (1+deltan^2*x^2)^(-3) * exp(-wn^2*x^2) )', $
/expression, 0., +inf)
endfor
print, A

stop
end


But I get the following error message:

% QPINT1D: USAGE:
% QPINT1D: G = QPINT1D(FUNCNAME, A, B, $
% QPINT1D: [EPSABS=, EPSREL=, ERROR=, STATUS=])
% QPINT1D: (or)
% QPINT1D: G = QPINT1D(EXPR, A, B, /EXPRESSION, $
% QPINT1D: [EPSABS=, EPSREL=, ERROR=, STATUS=])
NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN


Can anyone please let me know where I could be making a mistake? Thanks...
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 07-13-2012, 07:45 PM
Craig Markwardt
Guest
 
Posts: n/a
Default Re: Array Integration

On Friday, July 13, 2012 2:51:01 PM UTC-4, Maryam wrote:
> Hello.
>
> I am trying to perform a numerical integration in IDL where one of my variables is an array. Here is what I wrote:
>
> pro ind_intg
>
> delta=1.0
> W=[0.0212330,0.0424661,0.127398,0.212330,0.297263,0.4 24661,0.530826,0.636991,0.743157,0.849322,0.955487 ,1.06165,1.16782,1.27398]
> num_elements=14
> A = fltarr(num_elements)
> for i = 0, num_elements-1 do begin
> A(i) = qpint1d('((2.*!pi*deltan^4) * x * (1+deltan^2*x^2)^(-3) * exp(-wn^2*x^2) )', $
> /expression, 0., +inf)
> endfor
> print, A
>
> stop
> end
>
>
> But I get the following error message:
>
> % QPINT1D: USAGE:
> % QPINT1D: G = QPINT1D(FUNCNAME, A, B, $
> % QPINT1D: [EPSABS=, EPSREL=, ERROR=, STATUS=])
> % QPINT1D: (or)
> % QPINT1D: G = QPINT1D(EXPR, A, B, /EXPRESSION, $
> % QPINT1D: [EPSABS=, EPSREL=, ERROR=, STATUS=])
> NaN NaN NaN NaN NaN NaN NaN NaN NaN
> NaN NaN NaN NaN NaN
>
>
> Can anyone please let me know where I could be making a mistake? Thanks...


You need to pass PRIVATE data to your expression. At the time QPINT1D evaluates your expression, it doesn't know about DELTAN or WN.

Try this instead,
P = {wn:wn, deltan:deltan}
my_expression = '((2.*!pi*(P.deltan)^4) * x * (1+(P.deltan)^2*x^2)^(-3) * exp(-(P.wn)^2*x^2) )'
A[i] = qpint1d(my_expression, /expression, 0, +inf, P, ...)
Here "P" is the PRIVATE variable.

Craig
Reply With Quote
  #3 (permalink)  
Old 07-13-2012, 09:01 PM
Maryam
Guest
 
Posts: n/a
Default Re: Array Integration

Thank you, Sir, for your quick reply. I tried the following which produces a 14 element array of NaN's...:



pro ind_intg

delta=1.0
W=[0.0212330,0.0424661,0.127398,0.212330,0.297263,0.4 24661,0.530826,0.636991,0.743157,0.849322,0.955487 ,1.06165,1.16782,1.27398]

P = {w:w, delta:delta}
my_expression = '((2.*!pi*(P.delta)^4) * x * (1+(P.delta)^2*x^2)^(-3) * exp(-(P.w)^2*x^2) )'

num_elements=n_elements(W)
A = fltarr(num_elements)

for i = 0, num_elements-1 do begin
A[i] = qpint1d(my_expression, /expression, 0, +inf, P)
endfor

print, A

stop
END
Reply With Quote
  #4 (permalink)  
Old 07-14-2012, 02:04 AM
Craig Markwardt
Guest
 
Posts: n/a
Default Re: Array Integration

On Friday, July 13, 2012 5:01:49 PM UTC-4, Maryam wrote:
> Thank you, Sir, for your quick reply. I tried the following which produces a 14 element array of NaN's...:

....
> P = {w:w, delta:delta}



I'm guessing you want to make a new "P" for each loop iteration, with W[i] (and delta[i]?).
Reply With Quote
  #5 (permalink)  
Old 07-14-2012, 02:26 AM
Maryam
Guest
 
Posts: n/a
Default Re: Array Integration

delta stays the same, but you are right about "W".

I know how to do this if W was an integer, not an array. I would simply define a function and then use the QROMO command to find the value of the integral for a specific "W", but I don't know how to do this if W is an array. I tried to use the common block, but it doesn't work. I appreciate your help.
Reply With Quote
  #6 (permalink)  
Old 07-14-2012, 02:35 AM
Craig Markwardt
Guest
 
Posts: n/a
Default Re: Array Integration

On Friday, July 13, 2012 10:26:16 PM UTC-4, Maryam wrote:
> delta stays the same, but you are right about "W".
>
> I know how to do this if W was an integer, not an array. I would simply define a function and then use the QROMO command to find the value of the integral for a specific "W", but I don't know how to do this ifW is an array. I tried to use the common block, but it doesn't work. Iappreciate your help.


You mean like this?
P = {w:w[i], delta:delta}
Reply With Quote
  #7 (permalink)  
Old 07-14-2012, 03:01 AM
Maryam
Guest
 
Posts: n/a
Default Re: Array Integration

Yes, it should be W[i], but I don't think I got it right:


pro ind_intg

delta=1.0
W=[0.0212330,0.0424661,0.127398,0.212330,0.297263,0.4 24661,0.530826,0.636991,0.743157,0.849322,0.955487 ,1.06165,1.16782,1.27398]

num_elements=n_elements(W)

P = fltarr(num_elements)

for i = 0, num_elements-1 do begin
P[i] = {w:w[i], delta:delta}
my_expression = '((2.*!pi*(P.delta)^4) * x * (1+(P.delta)^2*x^2)^(-3) * exp(-(P.w)^2*x^2) )'
endfor

A = fltarr(num_elements)

for i = 0, num_elements-1 do begin
A[i] = qpint1d(my_expression, /expression, 0, +Inf, P)
endfor
print, A


stop
END
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 04:58 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.