f



how does it evaluate: y * w # A where:

Hi,
Please help me to understand as to how it is being evaluated and what
do I get from this entire operation:

 x= y * w # A

where:

y= an array of 'n' elements
w= an array of 'n' elements
A= a matrix of 'n' columns and 'm' rows

which operation is performed first: y*w or w # A

Thanks a lot,

Hassan
0
9/8/2003 2:01:13 PM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

6 Replies
988 Views

Similar Articles

[PageSpeed] 5

iqbal_hassan@extenprise.net (Hassan Iqbal) writes:

> Hi,
> Please help me to understand as to how it is being evaluated and what
> do I get from this entire operation:
> 
>  x= y * w # A
> 
> where:
> 
> y= an array of 'n' elements
> w= an array of 'n' elements
> A= a matrix of 'n' columns and 'm' rows
> 
> which operation is performed first: y*w or w # A

You've been asking this question, or ones like it, several times in
the past few days.  Why not perform some experiments for yourself?

For example, you could practice with these two expressions:
  x1 = (y * w) # A
  x2 = y * (w # A)
Do both expressions work?  If yes, are X1 and X2 different?  If both
expressions don't work, can you see why?

Your current question is about associativity.  Many languages have
left-to-right associativity, which means that operations with equal
precedence are paired left-first.  Do you think that is true for IDL?

However, different operators can have different precedences.  Can you
see what would happen if "*" (multiplication) were to be changed to
"+" (addition)?  Perhaps the "Operator Precedence" section of the IDL
manual would help figure that one out.

Good luck,
Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------
0
9/8/2003 2:26:57 PM
Hassan Iqbal writes:

> Please help me to understand as to how it is being evaluated and what
> do I get from this entire operation:
> 
>  x= y * w # A
> 
> where:
> 
> y= an array of 'n' elements
> w= an array of 'n' elements
> A= a matrix of 'n' columns and 'm' rows
> 
> which operation is performed first: y*w or w # A

What you want is some notion of operator precedence.
Try this:

   IDL> ? operators

Find the "precedence" sub-topic.

You find that the * operator has the third highest
precedence, whereas the # operator has the fourth
highest precedence. Thus, multiplication is done
before matrix operations. If operators have the
same order of precedence, then they are performed
left to right across the expression.

Cheers,

David

-- 
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
0
david3553 (839)
9/8/2003 2:36:49 PM
Craig Markwardt writes:

> You've been asking this question, or ones like it, several times in
> the past few days.  Why not perform some experiments for yourself?

I think every couple of months the planets align themselves
in such a way that we get a raft of people who want an answer
to a question, but not *THAT* answer! 

I don't know. I do know that EMACS *is* the answer! :-)

Cheers,

David

-- 
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
0
david3553 (839)
9/8/2003 2:43:30 PM
David  Fanning <david@dfanning.com> writes:
> You find that the * operator has the third highest
> precedence, whereas the # operator has the fourth
> highest precedence. Thus, multiplication is done
> before matrix operations. If operators have the
> same order of precedence, then they are performed
> left to right across the expression.

Hmm, David, in the manuals I've looked at, the # (matrix multiply) and
* (multiply) operators have the *same* precedence.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------
0
9/8/2003 11:28:49 PM
Craig Markwardt writes:

> Hmm, David, in the manuals I've looked at, the # (matrix multiply) and
> * (multiply) operators have the *same* precedence.

Oh, whoops! I must have been looking at pointer de-referencing.
The font is a bit tiny in my on-line help, and I had misplaced
my good glasses this morning (again!). :-)

Cheers,

David

-- 
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
0
david3553 (839)
9/9/2003 12:44:48 AM
David  Fanning <david@dfanning.com> wrote in message news:<MPG.19c6d067e7fa78f59896e1@news.frii.com>...
> Craig Markwardt writes:
> 
> > Hmm, David, in the manuals I've looked at, the # (matrix multiply) and
> > * (multiply) operators have the *same* precedence.
> 
> Oh, whoops! I must have been looking at pointer de-referencing.
> The font is a bit tiny in my on-line help, and I had misplaced
> my good glasses this morning (again!). :-)
> 
> Cheers,
> 
> David

Thanks Craig and David. If * and matrix # operators have the same
precedence and if operators with same precedence are evaluated left to
right then I am able to understand the things with the help from you
guys.
 Actually my online help on operators also shows * as having third
highest precedence and # as having fourth. That is why I was having
this whole lot of confusion.
 Thanks once again.
Hassan
0
9/10/2003 9:12:44 AM
Reply: