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

Home » Public Forums » archive » Re: Matrix filling methods?
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: Matrix filling methods? [message #2689 is a reply to message #2688] Fri, 19 August 1994 03:33 Go to previous message
sjt is currently offline  sjt
Messages: 72
Registered: November 1993
Member
Andy Nicholas (nicholas@dsuap1) wrote:
:
: I'm trying to speed up some code and hence I am trying
: to get rid of some FOR loops. I need to fill a 2-d square
: matrix. The values above the diagonal are given by one
: formula while those values below the diagonal are given
: by another. this is how i currently fill the matrix:


: for i=0,n-1 do begin
: Matrix(i:*,i-1) = x(i-1)/x(k:*)
: Matrix(i-1,i:*) = y(k:*)/y(k-1)
: endfor
: diag=findgen(n)
: Matrix(diag,diag)=z(diag)

: Does anyone know of a way to speed this up? Maybe a where to find the
: matrix elements above the diagonal and one for below?
: Any help is greatly appreciated,
: Thanks,
: Andy
: nicholas.uap.nrl.navy.mil
:

This should be no problem provied you have enough memory for several
arrays of size n. Here is the way I'd do it:

l = lindgen(n,n)
lc = l mod n
lr = l / n

upper = lc gt lr
lower = lc lt lr

Matrix = fltarr(n,n)
matrix(upper) = ...
matrix(lower) = ...

If you need to include the diagonal then just replace gt or lt with ge or le

--
James Tappin, School of Physics & Space Research
University of Birmingham
sjt@xun8.sr.bham.ac.uk
"If all else fails--read the instructions!"

O__
-- \/`
[Message index]
 
Read Message
Read Message
Previous Topic: Matrix filling methods?
Next Topic: Multiple graphs in IDL

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

Current Time: Fri Oct 10 23:06:16 PDT 2025

Total time taken to generate the page: 1.12087 seconds