Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 2 > Newsgroup comp.lang.idl

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2009, 10:12 PM
Nicki
Guest
 
Posts: n/a
Default Re: summation and 3d plot

Thanks a lot for the quick answer... So that is what my code looks
like now:

pro testif
nx=findgen(64)
ny=findgen(64)
x0=(30./32.*(0.5+nx))-30.
y0=(30./32.*(0.5+ny))-30.
N=findgen(10)
S=dblarr(n_elements(nx),n_elements(ny),n_elements( N))
phi=N*36*!pi/180
for i=0,n_elements(nx) do begin
for j=0,n_elements(ny) do begin
nrows=1.
dfov=60.
mu=438.689
ri=0.1
wdet=45.
r=50.
a=73.73
N=10
d=0.736
f=29.33
r0=sqrt(x0[i]^2+y0[j]^2)
if (r0 gt 30.) then S[i,j,*]=0 else begin
x=abs(x0*cos(phi)+y0*sin(phi))
y=-x0*sin(phi)+y0*cos(phi)
h=50.-y
deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180))
S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100
deffr=d+alog(2)/mu*tan(a/2*!pi/180)
R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2)
endelse
endfor
endfor
S_plot=total(S,3)
print, x0, y0, s_plot
;isurface,S_plot,x0,y0
end

However the r0 did not work. And there is another error. The error
message says "subscript range values of the form low:high must be >=0,
< size, with low <= high: S" and the error is in the S[i,j,*]=...
line...
What does that mean???
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 10-28-2009, 11:40 PM
pp
Guest
 
Posts: n/a
Default Re: summation and 3d plot

On Oct 28, 9:12*pm, Nicki <nickireite...@yahoo.de> wrote:

> However the r0 did not work. And there is another error. The error
> message says "subscript range values of the form low:high must be >=0,
> < size, with low *<= high: S" and the error is in the S[i,j,*]=...
> line...
> What does that mean???


There were a few typos. This should work:

pro testif
nrows=1.
dfov=60.
mu=438.689
ri=0.1
wdet=45.
r=50.
a=73.73
N=10
d=0.736
f=29.33
nx=findgen(64)
ny=findgen(64)
x0=(30./32.*(0.5+nx))-30.
y0=(30./32.*(0.5+ny))-30.
N=findgen(10)
S=dblarr(n_elements(nx),n_elements(ny),n_elements( N))
phi=N*36*!pi/180
for i=0,n_elements(nx)-1 do begin
for j=0,n_elements(ny)-1 do begin
r0=sqrt(x0[i]^2+y0[j]^2)
if (r0 gt 30.) then S[i,j,*]=0 else begin
x=abs(x0[i]*cos(phi)+y0[j]*sin(phi))
y=-x0[i]*sin(phi)+y0[j]*cos(phi)
h=50.-y
deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180))
S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100
deffr=d+alog(2)/mu*tan(a/2*!pi/180)
R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2)
endelse
endfor
endfor
S_plot=total(S,3)
print, x0, y0, s_plot
isurface,S_plot,x0,y0
end
Reply With Quote
  #3 (permalink)  
Old 10-30-2009, 02:55 AM
Jeremy Bailin
Guest
 
Posts: n/a
Default Re: summation and 3d plot

On Oct 28, 8:40*pm, pp <pp.pente...@gmail.com> wrote:
> On Oct 28, 9:12*pm, Nicki <nickireite...@yahoo.de> wrote:
>
> > However the r0 did not work. And there is another error. The error
> > message says "subscript range values of the form low:high must be >=0,
> > < size, with low *<= high: S" and the error is in the S[i,j,*]=....
> > line...
> > What does that mean???

>
> There were a few typos. This should work:
>
> pro testif
> nrows=1.
> dfov=60.
> mu=438.689
> ri=0.1
> wdet=45.
> r=50.
> a=73.73
> N=10
> d=0.736
> f=29.33
> nx=findgen(64)
> ny=findgen(64)
> x0=(30./32.*(0.5+nx))-30.
> y0=(30./32.*(0.5+ny))-30.
> N=findgen(10)
> S=dblarr(n_elements(nx),n_elements(ny),n_elements( N))
> phi=N*36*!pi/180
> for i=0,n_elements(nx)-1 do begin
> * for j=0,n_elements(ny)-1 do begin
> * * r0=sqrt(x0[i]^2+y0[j]^2)
> * * if (r0 gt 30.) then S[i,j,*]=0 else begin
> * * * x=abs(x0[i]*cos(phi)+y0[j]*sin(phi))
> * * * y=-x0[i]*sin(phi)+y0[j]*cos(phi)
> * * * h=50.-y
> * * * deffs=sqrt(d^2+2/mu*tan(a/2*!pi/180))
> * * * S[i,j,*]=deffs^2*(sin(atan(x/(h))))^3/(4*h)^2*100
> * * * deffr=d+alog(2)/mu*tan(a/2*!pi/180)
> * * * R=sqrt((h/f*ri)^2+(deffr*(h+f)/f)^2)
> * * endelse
> * endfor
> endfor
> S_plot=total(S,3)
> print, x0, y0, s_plot
> isurface,S_plot,x0,y0
> end


Can't you replace the for loops with:

nnx = n_elements(nx)
nny = n_elements(ny)
nN = n_elements(N)
x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN)
y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN)
phi = rebin(reform(phi,1,1,nN),nnx,nny,nN)
r0 = sqrt(x0^2 + y0^2)
x = abs(x0*cos(phi) + y0*sin(phi))
y = -x0*sin(phi) + y0*cos(phi)
h = 50.-y
deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.))
S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100.
deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.)
R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2)

-Jeremy.
Reply With Quote
  #4 (permalink)  
Old 10-30-2009, 03:12 AM
pp
Guest
 
Posts: n/a
Default Re: summation and 3d plot

On Oct 30, 1:55*am, Jeremy Bailin <astroco...@gmail.com> wrote:
> Can't you replace the for loops with:
>
> nnx = n_elements(nx)
> nny = n_elements(ny)
> nN = n_elements(N)
> x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN)
> y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN)
> phi = rebin(reform(phi,1,1,nN),nnx,nny,nN)
> r0 = sqrt(x0^2 + y0^2)
> x = abs(x0*cos(phi) + y0*sin(phi))
> y = -x0*sin(phi) + y0*cos(phi)
> h = 50.-y
> deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.))
> S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100.
> deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.)
> R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2)
>
> -Jeremy.


Yes, that is about what I was hinting at when I said it could be done
without loops. But given the initial question, I thought that jumping
directly to this level might make it difficult to understand.
Reply With Quote
  #5 (permalink)  
Old 10-30-2009, 04:09 PM
Jeremy Bailin
Guest
 
Posts: n/a
Default Re: summation and 3d plot

On Oct 30, 12:12*am, pp <pp.pente...@gmail.com> wrote:
> On Oct 30, 1:55*am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>
>
> > Can't you replace the for loops with:

>
> > nnx = n_elements(nx)
> > nny = n_elements(ny)
> > nN = n_elements(N)
> > x0 = rebin(reform(x0,nnx,1,1),nnx,nny,nN)
> > y0 = rebin(reform(y0,1,nny,1),nnx,nny,nN)
> > phi = rebin(reform(phi,1,1,nN),nnx,nny,nN)
> > r0 = sqrt(x0^2 + y0^2)
> > x = abs(x0*cos(phi) + y0*sin(phi))
> > y = -x0*sin(phi) + y0*cos(phi)
> > h = 50.-y
> > deffs = sqrt(d^2 + 2./mu*tan(a/2.*!pi/180.))
> > S = deffs^2 * sin(atan(x/h))^3 / (4.*h)^2 * 100.
> > deffr = d + alog(2.)/mu*tan(a/2.*!pi/180.)
> > R = sqrt((h/f*ri)^2 + (deffr*(h+f)/f)^2)

>
> > -Jeremy.

>
> Yes, that is about what I was hinting at when I said it could be done
> without loops. But given the initial question, I thought that jumping
> directly to this level might make it difficult to understand.


Oddly enough, I think this version is much more readable than the
looped version... I think that's a sign of doing too mcuh IDL
programming! ;-)

-Jeremy.
Reply With Quote
 
Reply

Popular Tags in the Forum
plot, summation

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 06:52 PM.


Copyright ©2009

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