0

I am new to IDL. I want to minimize code. I am writing this

for x=0,(pixel-1) do begin
    for y=0,(pixel-1) do begin
        for z=0,(pixel-1) do begin
        Bx[x,y,z]=-(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)
        endfor
    endfor
endfor

And I want to reduce to something like

x=dindgen(pixel)
y=dindgen(pixel)
z=dindgen(pixel)
Bx[x,y,z]=-(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)

How can I do it?

asynchronos
  • 583
  • 2
  • 14
Kartik Chhajed
  • 183
  • 2
  • 10

1 Answers1

1

Depending on the size of pixel you may not be able to create these arrays:

x = rebin(reform(dindgen(pixel), pixel, 1, 1), pixel, pixel, pixel)
y = rebin(reform(dindgen(pixel), 1, pixel, 1), pixel, pixel, pixel)
z = rebin(reform(dindgen(pixel), 1, 1, pixel), pixel, pixel, pixel)

But if you can, you should be able to do:

Bx = -(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)
mgalloy
  • 2,356
  • 1
  • 12
  • 10