Search   Memberlist   Usergroups
 Page 1 of 1 [5 Posts]
Author Message
lesshaste
science forum beginner

Joined: 12 Jun 2006
Posts: 2

Posted: Mon Jun 12, 2006 10:15 pm    Post subject: simple formula for svd of 2 by 2 array

Hi,

Does anyone know how to find a simple formula for the singular value
decomposition of a 2 by 2 array? I know I can use some general code for
svd but for speed I need something specialised as I will only ever be
considering 2 by 2 arrays.

Raphael
Robert B. Israel
science forum Guru

Joined: 24 Mar 2005
Posts: 2151

Posted: Tue Jun 13, 2006 5:30 am    Post subject: Re: simple formula for svd of 2 by 2 array

In article <448de77e$0$69392$ed2619ec@ptn-nntp-reader01.plus.net>, lesshaste <rcliffor@jesus.ox.ac.uk> wrote:  Quote: Does anyone know how to find a simple formula for the singular value decomposition of a 2 by 2 array? I know I can use some general code for svd but for speed I need something specialised as I will only ever be considering 2 by 2 arrays. Suppose your matrix is A (with real entries, I assume). B[1,1] := A[1,1]^2+A[2,1]^2; B[1,2] := A[1,1]*A[1,2]+A[2,1]*A[2,2]; B[2,2] := A[1,2]^2+A[2,2]^2; C[1,1] := A[1,1]^2+A[1,2]^2; C[1,2] := A[1,1]*A[2,1]+A[1,2]*A[2,2]; t := B[1,1]+B[2,2]; d := B[1,1]*B[2,2]-B[1,2]^2; r1 := (t+sqrt(t^2-4*d))/2; r2 := d/r1; h := sqrt(B[1,2]^2+(r1-B[1,1])^2); Q2[1,1] := B[1,2]/h; Q2[2,2] := Q2[1,1]; Q2[2,1] := (r1-B[1,1])/h; Q2[1,2] := -Q2[2,1]; k := sqrt(C[1,2]^2+(r1-C[1,1])^2); Q1[1,1] := C[1,2]/k; Q1[2,2] := Q1[1,1]; Q1[2,1] := (r1-C[1,1])/k; Q1[1,2] := -Q1[2,1]; The SVD is Q1 S Q2^T where S is diagonal with diagonal entries sqrt(r1) and sqrt(r2). Caution: this may produce divide-by-zero errors in some degenerate cases, or inaccurate results in some nearly-degenerate cases. I think I'll let you deal with those. Robert Israel israel@math.ubc.ca Department of Mathematics http://www.math.ubc.ca/~israel University of British Columbia Vancouver, BC, Canada lesshaste science forum beginner Joined: 12 Jun 2006 Posts: 2 Posted: Tue Jun 13, 2006 8:00 am Post subject: Re: simple formula for svd of 2 by 2 array Robert Israel wrote:  Quote: In article <448de77e$0$69392$ed2619ec@ptn-nntp-reader01.plus.net>, lesshaste wrote: Does anyone know how to find a simple formula for the singular value decomposition of a 2 by 2 array? I know I can use some general code for svd but for speed I need something specialised as I will only ever be considering 2 by 2 arrays. Suppose your matrix is A (with real entries, I assume). B[1,1] := A[1,1]^2+A[2,1]^2; B[1,2] := A[1,1]*A[1,2]+A[2,1]*A[2,2]; B[2,2] := A[1,2]^2+A[2,2]^2; C[1,1] := A[1,1]^2+A[1,2]^2; C[1,2] := A[1,1]*A[2,1]+A[1,2]*A[2,2]; t := B[1,1]+B[2,2]; d := B[1,1]*B[2,2]-B[1,2]^2; r1 := (t+sqrt(t^2-4*d))/2; r2 := d/r1; h := sqrt(B[1,2]^2+(r1-B[1,1])^2); Q2[1,1] := B[1,2]/h; Q2[2,2] := Q2[1,1]; Q2[2,1] := (r1-B[1,1])/h; Q2[1,2] := -Q2[2,1]; k := sqrt(C[1,2]^2+(r1-C[1,1])^2); Q1[1,1] := C[1,2]/k; Q1[2,2] := Q1[1,1]; Q1[2,1] := (r1-C[1,1])/k; Q1[1,2] := -Q1[2,1]; The SVD is Q1 S Q2^T where S is diagonal with diagonal entries sqrt(r1) and sqrt(r2). Caution: this may produce divide-by-zero errors in some degenerate cases, or inaccurate results in some nearly-degenerate cases. I think I'll let you deal with those. Robert Israel israel@math.ubc.ca Department of Mathematics http://www.math.ubc.ca/~israel University of British Columbia Vancouver, BC, Canada

Thanks, that's a wonderful answer. Did you work all the details out by
hand or did you find a way to get maple to help?

Raphael
Robert B. Israel
science forum Guru

Joined: 24 Mar 2005
Posts: 2151

Posted: Tue Jun 13, 2006 6:28 pm    Post subject: Re: simple formula for svd of 2 by 2 array

lesshaste wrote:
 Quote: Robert Israel wrote: In article <448de77e$0$69392\$ed2619ec@ptn-nntp-reader01.plus.net>, lesshaste wrote: Does anyone know how to find a simple formula for the singular value decomposition of a 2 by 2 array? I know I can use some general code for svd but for speed I need something specialised as I will only ever be considering 2 by 2 arrays. Suppose your matrix is A (with real entries, I assume). B[1,1] := A[1,1]^2+A[2,1]^2; B[1,2] := A[1,1]*A[1,2]+A[2,1]*A[2,2]; B[2,2] := A[1,2]^2+A[2,2]^2; C[1,1] := A[1,1]^2+A[1,2]^2; C[1,2] := A[1,1]*A[2,1]+A[1,2]*A[2,2]; t := B[1,1]+B[2,2]; d := B[1,1]*B[2,2]-B[1,2]^2; r1 := (t+sqrt(t^2-4*d))/2; r2 := d/r1; h := sqrt(B[1,2]^2+(r1-B[1,1])^2); Q2[1,1] := B[1,2]/h; Q2[2,2] := Q2[1,1]; Q2[2,1] := (r1-B[1,1])/h; Q2[1,2] := -Q2[2,1]; k := sqrt(C[1,2]^2+(r1-C[1,1])^2); Q1[1,1] := C[1,2]/k; Q1[2,2] := Q1[1,1]; Q1[2,1] := (r1-C[1,1])/k; Q1[1,2] := -Q1[2,1]; The SVD is Q1 S Q2^T where S is diagonal with diagonal entries sqrt(r1) and sqrt(r2). Caution: this may produce divide-by-zero errors in some degenerate cases, or inaccurate results in some nearly-degenerate cases. I think I'll let you deal with those. Robert Israel israel@math.ubc.ca Department of Mathematics http://www.math.ubc.ca/~israel University of British Columbia Vancouver, BC, Canada Thanks, that's a wonderful answer. Did you work all the details out by hand or did you find a way to get maple to help?

Mostly by hand, with some help and verification by Maple.

Robert Israel israel@math.ubc.ca
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada
Richard J. Fateman

Joined: 04 May 2005
Posts: 81

 Posted: Tue Jun 13, 2006 7:55 pm    Post subject: Re: simple formula for svd of 2 by 2 array Macsyma provides an answer from svd(A) where the matrix A is 2x2. The first line is a TeX comment with the input form. The rest is a TeX version. Another command "optimize" picks out common subexpressions in the two parts of the list. I suspect this is equivalent to Rob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}}+a^{2}_{2,2}+a^{2% }_{2,1}+a^{2}_{1,2}+a^{2}_{1,1}}}\over{\sqrt{2}}}\right\}$$

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Page 1 of 1 [5 Posts]
 The time now is Tue Mar 19, 2019 9:38 am | All times are GMT
 Jump to: Select a forum-------------------Forum index|___Science and Technology    |___Math    |   |___Research    |   |___num-analysis    |   |___Symbolic    |   |___Combinatorics    |   |___Probability    |   |   |___Prediction    |   |       |   |___Undergraduate    |   |___Recreational    |       |___Physics    |   |___Research    |   |___New Theories    |   |___Acoustics    |   |___Electromagnetics    |   |___Strings    |   |___Particle    |   |___Fusion    |   |___Relativity    |       |___Chem    |   |___Analytical    |   |___Electrochem    |   |   |___Battery    |   |       |   |___Coatings    |       |___Engineering        |___Control        |___Mechanics        |___Chemical

 Topic Author Forum Replies Last Post Similar Topics A simple question? qing3000@googlemail.com Electromagnetics 2 Tue Jul 18, 2006 2:31 pm Stumped with figuring a formula... moriman Recreational 8 Mon Jul 17, 2006 12:21 am simple DE/IVP, or is it? LookSkywalker@gmail.com Math 3 Sun Jul 16, 2006 10:02 pm (humor) Another hand-waving incredibly simple proof of FLT DGoncz@aol.com Math 0 Fri Jul 14, 2006 7:50 pm Simple factoring result, but what about lies? jstevh@msn.com Recreational 7 Fri Jul 14, 2006 12:52 am