comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: summation and 3d plot
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: summation and 3d plot [message #68388] Wed, 28 October 2009 17:40 Go to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
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
Re: summation and 3d plot [message #68389 is a reply to message #68388] Wed, 28 October 2009 16:12 Go to previous messageGo to next message
Nicki is currently offline  Nicki
Messages: 14
Registered: September 2009
Junior Member
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???
Re: summation and 3d plot [message #68419 is a reply to message #68389] Tue, 27 October 2009 03:54 Go to previous messageGo to next message
pfp is currently offline  pfp
Messages: 12
Registered: July 2009
Junior Member
On Oct 27, 6:19 am, Nicki <nickireite...@yahoo.de> wrote:
> Hey!
> I have two problems... First of all I need to sum up something. it
> should be pretty easy but i just get really confused with my arrays.
> first i have the following:
> nx=findgen(64.)
> ny=findgen(64.)
> for i=0,63 do begin
> for j=0,63 do begin
> x0=(30./32.*(0.5+nx[i]))-30.
> y0=(30./32.*(0.5+ny[j]))-30.
> .......
> N=findgen(10.)
> r0=sqrt(x0^2+y0^2)
> if (r0 gt 30.) then S=0 $   ; as it's an area of an circle with radius
> 30 (but not important for my problem)
> else begin
> for k=0,9 do begin
> phi=N[k]*36*!pi/180
> 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)
> endfor
> endelse
> endfor
> endfor
> end
>
> So what i wanna do now is summing up all "S" over k like "stot=s[k=0]+s
> [k=1]+....+s[k=9]" and then i want to have a 3 D plot of x0, y0 and
> stot  (however i have no idea how to do that either...).
> i know that a summation is usually done with "total(s)" but i don't
> know how to tell idl that it should be a summation over k. And i know
> that there are different ways how to do the 3D plot, but i don't
> really get the commands...
> i actually only want to have a 3D surface plot...
>

First, let me say that this can probably be done without loops (I only
say probably, instead of surely, because of what may happen in
the ..... lines). But that is another story.

It seems that what you want at the end is a variable (I will call it
S_plot) that is a function of x0 and y0. So at that point S_plot
should be a 2D array of dimensions 64,64. But this sum you mention
means that this S_plot comes from summing some variable S that you
calculate, which is a function of x0, y0 and phi over phi. So this S
must be a 3D array, with dimensions 64,64,N. Also, at the end you need
a 1D array with the values of x0, and a 1D array with the values of
y0, to make the surface plot.

With that in mind, your code should look more like

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
.......
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)
isurface,S_plot,x0,y0
end

Note that now x0, y0, phi, x, y, h and R are 1D arrays, and S is a 3D
array. Also I got rid of the loop in phi, it was unnecessary, it was
just cluttering and slowing the code. As I said, the loops over i and
j are probably unnecessary too.
Re: summation and 3d plot [message #68515 is a reply to message #68388] Thu, 29 October 2009 20:55 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: TLB_Frame_Attr weirdness/compile issue?
Next Topic: plot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:09:00 PDT 2025

Total time taken to generate the page: 0.00911 seconds