From help-request at octave dot org Fri Jun 4 13:49:01 2004 Subject: Re: calculating the eigen matrix From: Quentin Spencer To: tapesh at erudent dot com CC: help at octave dot org Date: Fri, 04 Jun 2004 13:47:23 -0500 The fill operator will work in this context, but it was really designed for filling parts of arrays bigger than a single element. For single-element assignments, the octave classes have overloaded the () operators to duplicate octave-style syntax in C++, so you can do something like this: //a = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]; a(0,0)=1; a(0,1)=1; a(0,2)=2; a(1,0)=3; a(1,1)=5; a(1,2)=13; a(2,0)=13; a(2,1)=21; a(2,2)=34; Of course you could do all of this in a FOR loop if you were copying from a C-style array to an octave Matrix type. -Quentin Tapesh wrote: >Hi Quentin, > >Thanks for your reply. >It is working perfectly fine.. > >Could you please also help me in one other problem? I have C style > array and I want to create Matrix out of it. I didn't find any >constructor which take the double[] and create matrix. > >Currently I am doing like this: (using the fill() function) >Matrix a(3,3); > //a = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]; > a.fill(1,0,0,0,0); > a.fill(1,0,1,0,1); > a.fill(2,0,2,0,2); > > a.fill(3,1,0,1,0); > a.fill(5,1,1,1,1); > a.fill(8,1,2,1,2); > > a.fill(13,2,0,2,0); > a.fill(21,2,1,2,1); > a.fill(34,2,2,2,2); > >Is this the right way? I am not confident if it is the efficient way to >do it. > > >Thanks in advance, >Tapesh > > >-----Original Message----- >From: Quentin Spencer [mailto:qspencer at ieee dot org] >Sent: Friday, June 04, 2004 9:20 PM >To: tapesh at erudent dot com >Cc: help at octave dot org >Subject: Re: calculating the eigen matrix > >This is from some old code I wrote: > >ComplexMatrix R(size,size), V(size,size); >// Assign R to something... >V = EIG(R).eigenvectors(); > >Note that the data type doesn't have to be ComplexMatrix--it could also >be just Matrix. I only needed the eigenvectors in this particular >application. If you wanted both eigenvalues and eigenvectors, a better >way would probably be something like this: > >EIG EVD; >Matrix A,B; >ColumnVector c; >// Assign A to something... >EVD=EIG(A); >B=EVD.eigenvectors(); >c=EVD.eigenvalues(); > >This code is untested--just based on what I remember from doing this >sort of thing in the past. I hope this helps. > >Regards, >Quentin Spencer > > > >Tapesh wrote: > > > >>Hi, >> >> >> >>I am writing an application in C/C++ and want to use Octave library to >> >> > > > >>calculate the eigen matrix and eigen-values. >> >> >> >>I am able to compile octave successfully and to write a sample C++ >>programme. >> >> >> >>Can someone provide a sample code to calculate eigen vectors? >> >> >> >> >> >>Thanks in Advance, >> >>Tapesh Kr. Agarwal >> >> >> >> >> > > > > > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------