0

I'm trying to make a contour plot in IDL of quantity described by and equation, which here I'll take to be x^2 + y. In order to do that, I first need to create a 2D array ("pxx").

Being a novice, I'm currently just moving my fist step into this direction and so far I've been trying to make this simpler foreach loop work:

pxx=fltarr(10, 10)

xx = indgen(10)
yy = indgen(10)

foreach k, xx do begin
  pxx[k,*]=3*k
endforeach
  
print, pxx

But this only seems to work for the last column. Any idea on how to fix that? And how would you suggest I proceed to create a 2D array in space for the equation above? Thank you in advance, any help is appreciated

Dai
  • 141,631
  • 28
  • 261
  • 374

1 Answers1

0

Choose the range of x and y values you want to evaluate on:

n = 10
x = findgen(n) - (n - 1)/2.0
y = findgen(n) - (n - 1)/2.0

Expand x and y to 2-dimensional versions of themselves:

xx = rebin(reform(x, n, 1), n, n)
yy = rebin(reform(y, 1, n), n, n)

Evaluate the function:

z = xx^2 + yy

Plot:

contour, z, x, y
mgalloy
  • 2,356
  • 1
  • 12
  • 10