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

Home » Public Forums » archive » 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
summation and 3d plot [message #68421] Tue, 27 October 2009 01:19 Go to next message
Nicki is currently offline  Nicki
Messages: 14
Registered: September 2009
Junior Member
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...

Can somebody please help me out?

Cheers,
Nicki
Re: summation and 3d plot [message #68498 is a reply to message #68421] Fri, 30 October 2009 10:09 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
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.
Re: summation and 3d plot [message #68513 is a reply to message #68421] Thu, 29 October 2009 21:12 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
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.
Re: summation and 3d plot [message #68514 is a reply to message #68421] Thu, 29 October 2009 21:00 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeremy Bailin writes:

> 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)

You gotta love people who have too much time on
their hands! :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problems with dialog_pickfile and JavaBridge
Next Topic: weird contour lines

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

Current Time: Wed Oct 08 13:58:06 PDT 2025

Total time taken to generate the page: 0.00523 seconds