I believe that the example below shows one way and perhaps as efficient a way as any. The basic algorithm was to recast the above problem as a multiplication of two same-sized 2D arrays, one of which held the El-based data (and columns of 1's as needed) and the other which held the Az-based data. To make the 2D arrays I simply reformed the vector data into 2D column data and appended the columns with the simplest possible array syntax. My example, then:
; Make some easy-to-debug example data
El = findgen(4) * 45. * !DTOR
Az = (findgen(4) * 30. + 30.) * !DTOR
print, 'cos(El) = ', string(cos(El), FORMAT='(4D8.3)')
; 1.000 0.707 -0.000 -0.707
print, 'sin(El) = ', string(sin(El), FORMAT='(4D8.3)')
; 0.000 0.707 1.000 0.707
print, 'cos(Az) = ', string(cos(Az), FORMAT='(4D8.3)')
; 0.866 0.500 -0.000 -0.500
print, 'sin(Az) = ', string(sin(Az), FORMAT='(4D8.3)')
; 0.500 0.866 1.000 0.866
; Make a matrix with nRows = n_elements(El)
; and columns [cos(El), cos(El), sin(El), 1.0]
nRows = n_elements(El)
ElCos = reform(cos(El), 1, nRows)
onesCol = replicate(1., 1, nRows)
; Now we just append the "columnized" data to form the 4 col by nRows operands
operand1 = $
[ElCos, ElCos, reform(sin(El), 1, nRows), onesCol]
; Make a matrix with same number of rows, but
; columns [cos(Az), sin(Az), 1.0, 1.0]
operand2 = $
[reform(cos(Az), 1, nRows), reform(sin(Az), 1, nRows), onesCol, onesCol]
print, 'Operand1:
print, operand1, FORMAT='(4D8.3)'
; 1.000 1.000 0.000 1.000
; 0.707 0.707 0.707 1.000
; -0.000 -0.000 1.000 1.000
; -0.707 -0.707 0.707 1.000
print, 'Operand2:'
print, operand2, FORMAT='(4D8.3)'
; 0.866 0.500 1.000 1.000
; 0.500 0.866 1.000 1.000
; -0.000 1.000 1.000 1.000
; -0.500 0.866 1.000 1.000
G = operand1 * operand2
print, '[cos(El)*cos(Az), cos(El)*sin(Az), sin(El), 1.0]'
print, G, FORMAT='(4D8.3)'
; 0.866 0.500 0.000 1.000
; 0.354 0.612 0.707 1.000
; 0.000 -0.000 1.000 1.000
; 0.354 -0.612 0.707 1.000
(I assume, by the way, that EI and Az must have the same number of elements, no? My example and discussion above, assumes that.)
James Jones
|