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

Home » Public Forums » archive » Re: Matlab Syntax
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Matlab Syntax [message #37026] Thu, 20 November 2003 13:09 Go to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
David Fanning wrote:
> Aaaaahhhhha. Never mind. Seeing it in print somewhere
> other than in the normal setting illuminated the problem
> immediately. Don't you love the way you have to embarrass
> yourself to gain enlightenment. :-)

Yeah. Do it all the time.

BTW that WWW page I mentioned is on your site:

http://www.dfanning.com/misc_tips/colrow_major.html


--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Matlab Syntax [message #37027 is a reply to message #37026] Thu, 20 November 2003 12:58 Go to previous messageGo to next message
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
On Thu, 20 Nov 2003 13:38:48 -0700, David Fanning put fingers to keyboard
and said:

> Folks,
>
> I need more Matlab help. Here is the line I am
> struggling with:
>
> invAI = inv(A + gamma * diag(ones(1,N)));

Adds 1 to each element of the diagonal

> invARRAY = Invert((ARRAY + gamma) ## Diag_Matrix(Replicate(1,npts)) )

adds 1 to each element of the array...

You need to decide which it is you want to do :-)

Bruce

--
+-------------------+--------------------------------------- ------------+
Bruce Bowler | Praise makes good men better and bad men worse. -
1.207.633.9600 | Thomas Fuller
bbowler@bigelow.org |
+-------------------+--------------------------------------- ------------+
Re: Matlab Syntax [message #37028 is a reply to message #37027] Thu, 20 November 2003 12:56 Go to previous messageGo to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
David Fanning wrote:
> Folks,
>
> I need more Matlab help. Here is the line I am
> struggling with:

I find randomly adding IDL transpose() calls helps.

No I am not joking. The relation between index (i,j) order and printing
(row, column) order is not the same in IDL as in Matlab.

There's a good WWW page about it somewhere.

Oops, sorry, I didn't follow your advice of the other day to spend
several minutes thinking before posting. (For heaven's sake, David, if I
did that I would never post anything.) Please ignore it.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Matlab Syntax [message #37029 is a reply to message #37028] Thu, 20 November 2003 12:52 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> I need more Matlab help.

Aaaaahhhhha. Never mind. Seeing it in print somewhere
other than in the normal setting illuminated the problem
immediately. Don't you love the way you have to embarrass
yourself to gain enlightenment. :-)

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
Re: Matlab Syntax [message #37030 is a reply to message #37029] Thu, 20 November 2003 13:44 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
David Fanning wrote:
>
> Folks,
>
> I need more Matlab help. Here is the line I am
> struggling with:
>
> invAI = inv(A + gamma * diag(ones(1,N)));
>
> A is a matrix and gamma is the scalar 1.0.
>
> Here is the output from Matlab when I print
> A and invAI:
>
> A =
> 8 -5 1 1 -5
> -5 8 -5 1 1
> 1 -5 8 -5 1
> 1 1 -5 8 -5
> -5 1 1 -5 8
>
> invAI =
>
> 0.3158 0.2105 0.1316 0.1316 0.2105
> 0.2105 0.3158 0.2105 0.1316 0.1316
> 0.1316 0.2105 0.3158 0.2105 0.1316
> 0.1316 0.1316 0.2105 0.3158 0.2105
> 0.2105 0.1316 0.1316 0.2105 0.3158
>
> I have the matrix A in my IDL session:
>
> IDL> print, array
> 8.00000 -5.00000 1.00000 1.00000 -5.00000
> -5.00000 8.00000 -5.00000 1.00000 1.00000
> 1.00000 -5.00000 8.00000 -5.00000 1.00000
> 1.00000 1.00000 -5.00000 8.00000 -5.00000
> -5.00000 1.00000 1.00000 -5.00000 8.00000
>
> But I get the wrong answers when I invert. Here is
> my translation of the Matlab inverse line:
>
> invARRAY = Invert((ARRAY + gamma) ## Diag_Matrix(Replicate(1,npts)) )

I know nothing special about Matlab, but the matlab equation seems
pretty clear. I assume that inv() and Invert() do the same thing, and
that diag() and Diag_Matrix() serve the same purpose, and that ones(1,N)
does the same thing as Replicate(1,npts). If so, then unless I'm
massively confused (which is possible), shouldn't that be:

invARRAY = Invert((ARRAY + gamma * Diag_Matrix(Replicate(1,npts))) )
Re: Matlab Syntax [message #37031 is a reply to message #37029] Thu, 20 November 2003 12:38 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Folks,

I need more Matlab help. Here is the line I am
struggling with:

invAI = inv(A + gamma * diag(ones(1,N)));

A is a matrix and gamma is the scalar 1.0.

Here is the output from Matlab when I print
A and invAI:

A =
8 -5 1 1 -5
-5 8 -5 1 1
1 -5 8 -5 1
1 1 -5 8 -5
-5 1 1 -5 8

invAI =

0.3158 0.2105 0.1316 0.1316 0.2105
0.2105 0.3158 0.2105 0.1316 0.1316
0.1316 0.2105 0.3158 0.2105 0.1316
0.1316 0.1316 0.2105 0.3158 0.2105
0.2105 0.1316 0.1316 0.2105 0.3158

I have the matrix A in my IDL session:

IDL> print, array
8.00000 -5.00000 1.00000 1.00000 -5.00000
-5.00000 8.00000 -5.00000 1.00000 1.00000
1.00000 -5.00000 8.00000 -5.00000 1.00000
1.00000 1.00000 -5.00000 8.00000 -5.00000
-5.00000 1.00000 1.00000 -5.00000 8.00000

But I get the wrong answers when I invert. Here is
my translation of the Matlab inverse line:

invARRAY = Invert((ARRAY + gamma) ## Diag_Matrix(Replicate(1,npts)) )

Here is what I get:

0.185455 0.0581818 -0.0509091 -0.0509091 0.0581818
0.0581818 0.185455 0.0581818 -0.0509091 -0.0509091
-0.0509091 0.0581818 0.185455 0.0581818 -0.0509091
-0.0509091 -0.0509091 0.0581818 0.185455 0.0581818
0.0581818 -0.0509091 -0.0509091 0.0581818 0.185455

I'm pulling my hair out here! Can someone help?

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
Re: Matlab Syntax [message #37145 is a reply to message #37031] Tue, 18 November 2003 02:16 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
David Fanning wrote:
> Folks,
>
> Speaking of Matlab syntax (which I am beginning to like,
> by the way), here is one I find confusing. Any Matlab
> users out there in IDL-land?
>
> y(2*x(IDX==0))=[];
>
> IDX is a vector, I think. The variables x and y
> are vectors for sure. I realize IDL doesn't
> have a null array, but my best guess about this
> translation is something like this.
>
> I = Where(IDX EQ 0, count)
> IF count GT 0 THEN y[2*x[I]] = !Values.F_NAN
>
> Is that close?

Assigning an element to [] is a simple way to delete it.
e.g.

>> a=[1,2,3,4]
a =
1 2 3 4
>> a(3)=[]
a =
1 2 4



--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Byte Swapping
Next Topic: PostScript output from iTools

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

Current Time: Sun Oct 12 09:25:18 PDT 2025

Total time taken to generate the page: 1.12171 seconds