Re: Initialize a Diagonal Matrix
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Sun, 10 Sep 2006 08:45:29 -0700
<michael@xxxxxxxxxxxxxxxx> wrote:
Other than using a DO loop is there any compact way of initializing the
elements of a diagonal matrix. For a vector one can write,
v(:)=(/1,3,10/). Is there something similar for a diagonal matrix?
Mostly, no. I think I might have seen an obscure related trick but I
don't recall the details and I might even misrecall having seen such a
thing. If it existed, it certainly wasn't anything that you'd actually
want to do other than to win a bet or some such thing.
I'm slightly puzzled in two ways about your mention of DO loops.
First, I feel obligated to ask what is wrong with DO loops. I ask
becasue there are some people who seem to have what I can only regard as
a prejuice against DO loops, thinking that they are somehow
intrinsically inferior to newer features of the language. I disagree
with that.
That aside, I have trouble imagining exactly what you are talking about
in DO loops. I don't know of a simple direct way to do this using DO
loops either. If I had a very small (say 3x3) array, I'd probably just
set it to 0 and then individually assign each of the diagonal elements.
If I had an array that was much larger than that ·or was dynamically
sized), I'd likely initialize a temporary rank 1 array for the diagnonal
elements and then use a DO loop to copy that to the diagonal of the
rank-2 array. Perhaps you meant something like that, but I wasn't quite
sure whether you had something else in mind, since I would say that the
main characterization of that method is that it uses a temporary rank-1
array for the diagonal; the DO loop seems like a smaller detail.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Initialize a Diagonal Matrix
- From: Jugoslav Dujic
- Re: Initialize a Diagonal Matrix
- From: michael
- Re: Initialize a Diagonal Matrix
- From: Brooks Moses
- Re: Initialize a Diagonal Matrix
- References:
- Initialize a Diagonal Matrix
- From: michael
- Initialize a Diagonal Matrix
- Prev by Date: Re: Logical handling
- Next by Date: Re: Logical handling
- Previous by thread: Re: Initialize a Diagonal Matrix
- Next by thread: Re: Initialize a Diagonal Matrix
- Index(es):
Relevant Pages
|