Results 1 to 16 of 16

Thread: Fractional Powers of a Matrix

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Fractional Powers of a Matrix

    Hi everyone ,
    I want to calculate fractional power of a matrix. How i will do it ? Is there any class related to matrix in qt ?

    with regards
    bibhu

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Fractional power of a matrix? Is that element wise? Otherwise I can't imagine how that should work. Anyhow, Qt doesn't have anyhting matrix related, but Armadillo is an excellent and simple matrix library.

  3. #3
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Thanks for reply,

    If A is a matrix of 2x2 then A^2 means multiply matrix A with itself (means A X A).

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Sure, but what would be A^1.5? Since you're saying fractional powers.

  5. #5
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Actually i also do not know how to calculate A^1.5 .
    It may be like A^(3/2) = sqrt(A^3).

    Actually i want to apply a equation like g(x,y) = iFFT { FFT(u,v) X |FFT(u,v)|^k } where 0 < k <1 |FFT(u,v)| is also a u X v matrix.

  6. #6
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Oh in that case Armadillo is no help, it's only good for simple linear algebra. With fourier transformation I'm afraid you gonna have to try a heavier gun, such as the GSL library. It has matrix classes and readily implemented fourier transformation functions.

  7. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Fractional Powers of a Matrix

    Actually i also do not know how to calculate A^1.5 .
    It may be like A^(3/2) = sqrt(A^3).
    Really ?
    Qt Code:
    1. A^(3/2) = sqrt(A^3) // your equation
    2. let B = A^3, then
    3. sqrt(A^3) = sqrt(B) = B^(1/2) // and what could that be ? ;)
    To copy to clipboard, switch view to plain text mode 
    If I remember correctly (forgive me any mistakes, I've passed the linear algebra course 4 yeas ago), fractional power of a (square) matrix is computed this way:
    Let A be n x n matrix, then eigenvalues of A are the roots of a polynomial P(x) = det(A-x*I), where I is identity matrix of the same size as A. For each eigenvalue there is a corresponding eigenvector v_i, such that:
    (1) A * v_i = e_i * v_i (e_i - i-th eigenvalue)
    Above equation applies to any Natural number n:
    (2) A^n * v_i = (e_i ^ n) * v_i (this can be easily proven by induction)
    We can generalize this to any Rational number r instead of n (I dont remember the proof).
    So in order to calculate A^x, where x is Rational number you need to find just one eigenvalue and corresponding eigenvector.

    Simple example:
    A = ( 3 1, 2 2 ) (row1, row2) (ok, this example is prepared such that roots are easily computed, but its only to show the method)
    P(x) = det( A - x*I ) = det( 3-x 1, 2 2-x ) = (3-x)(2-x) - 2 = x^2 - 5x + 4 = (x-4)(x-1)
    P(x) == 0 <=> x in { 4, 1 }
    Eigenvector v=(x,y) for value 4 (equation (1)):
    A* (x, y) = 4*(x,y)
    (3x + y, 2x + 2y) = (4x, 4y) <=> x=y, so we may take any value, lets use x=y=2
    v = (2,2)
    Lets compute A^(3/2) (equation (2)):
    A^(3/2) * v = 4^(3/2) * v
    A^(3/2) * (2,2) = (2*4^(3/2), 2*4^(3/2))
    Let A^(3/2) = B = (a b, c d) =>
    (a b, c d)*(2,2) = (2*4^(3/2),2*4^(3/2)) => (calculated on paper) =>
    a = 5/3, b = 1/3, c = 1/3, d = 4/3 (if im not wrong)

    So A^(3/2) = (5/3 1/3, 1/3 4/3)

    I used to do the calculations much quicker, I'm getting old :P

  8. #8
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Thanks stampede,
    In my case the matrix A is a image of 256X256.So if i want to calculate the eigenvalue the i think i have to solve a polynomial of 256 power.How i will solve this ? According to my knowledge solving polynomial is slower.Can you tell me how to do this things ?

  9. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Fractional Powers of a Matrix

    I don't think you should implement fractional matrix powers yourself if you care about speed. I'd just use one of available scientific libraries (like already linked GSL). My example was just to show the relevant math ( because you said "i also do not know how to calculate A^1.5", so now you know ).

  10. #10
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    I had used matlab to calculate the fractional power of a square matrix of 256 X 256.It is faster.So i thought there should be any algorithm to do this.Is there any alternative or any shortcut for this ?

  11. #11
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Fractional Powers of a Matrix

    It is faster
    It is faster than what ? GSL ?
    So i thought there should be any algorithm to do this
    Yes, there is, in GSL (or alike) library.
    There is no such algorithms like Fourier Transforms in Qt, remember that this is mostly a GUI framework, you need to mix Qt with external libraries to provide additional functionality (like GSL for advanced math, libraries for serial port communication, video processing etc... )

  12. #12
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Fractional Powers of a Matrix

    Just a side note: GSL is offered under the Gnu GPL. Using it in your code poses a significant threat to retaining control of your code. There are other mathematical libraries out there that provide matrix capabilities. If you're planning on distributing your software, you'll probably want to consult an attorney before committing to the GSL, or to any other packaged software that may place restrictions on distribution.

  13. #13
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fractional Powers of a Matrix

    Form mathematical point of view it is possible.
    There is a way to apply any analytical function on matrix.
    First you have to expand function to taylor-polynomial. Since you can't calculate fractional power of negative value central point must be some bigger value (1 is convinient)
    From that point it is ease to use this polynomial to calculate value of function for matrix.
    so assuming that power is >0 it will be something like that:
    Qt Code:
    1. typedef SommatrixClas Matrix;
    2.  
    3. Matrix power(cons Matrix &A, qreal pow) {
    4. Q_ASSERT(pow>0);
    5. Q_ASSERT(A.columnCount()==A.rowCount());
    6. Matrix result = A;
    7. Matrix b = 1;
    8. Matrix old = 0;
    9. for (int i=1; !qFuzzyCompare(result, old); ++i) {
    10. b *= A * (pow/i);
    11. pow-= 1.0;
    12. old = result;
    13. result += pow;
    14. }
    15. return result;
    16. }
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    thanks MarekR22

    But what is the use of b.

  15. #15
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fractional Powers of a Matrix

    Ha, your question coused that i fond error in my code .
    Qt Code:
    1. typedef SommatrixClas Matrix;
    2.  
    3. Matrix power(cons Matrix &A, qreal pow) {
    4. Q_ASSERT(pow>0);
    5. Q_ASSERT(A.columnCount()==A.rowCount());
    6. Matrix result = A;
    7. Matrix x = A - 1; // here A has to be "moved" to take into account x0!
    8. Matrix b = 1;
    9. Matrix old = 0;
    10. for (int i=1; !qFuzzyCompare(result, old); ++i) {
    11. b *= x * (pow/i);
    12. pow-= 1.0;
    13. old = result;
    14. result += b; // here was mistake too
    15. }
    16. return result;
    17. }
    To copy to clipboard, switch view to plain text mode 

    This is just a concept demonstration, for example qFuzzyCompare should be replaced with some better condition of ending polynomial calculation, implementation can also change depending on used matrix class.

  16. #16
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Fractional Powers of a Matrix

    Can you explain me what is the meaning of A - 1 and X * (pow/i) [ if A = {1 2, 3 4} then A - 1 = ? ] ?

Similar Threads

  1. LED Matrix
    By jwflammer in forum Newbie
    Replies: 1
    Last Post: 23rd February 2011, 01:23
  2. glRotetef & 4x4 Matrix
    By wererabit in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2011, 09:39
  3. QGraphicsScene and matrix
    By Artturi.Sakari in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2010, 11:49
  4. need help with creating an m x n matrix
    By Petr_Kropotkin in forum General Programming
    Replies: 3
    Last Post: 3rd April 2010, 15:18
  5. matrix for QBrush
    By navi1084 in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2010, 11:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.