Re: Matlab Syntax [message #37026] |
Thu, 20 November 2003 13:09  |
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 #37030 is a reply to message #37029] |
Thu, 20 November 2003 13:44  |
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  |
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  |
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
|
|
|