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 
Return to the default flat view Create a new topic Submit Reply
Re: summation and 3d plot [message #68419 is a reply to message #68389] Tue, 27 October 2009 03:54 Go to previous messageGo to previous 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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: TLB_Frame_Attr weirdness/compile issue?
Next Topic: plot

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

Current Time: Fri Oct 10 15:08:20 PDT 2025

Total time taken to generate the page: 0.56142 seconds