Author 
Message 
Richard J. Fateman science forum addict
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 Robert Israel's and
has similar prospects for division by zero.
RJF
%[SQRT(SQRT(A[2,2]^4+(2*A[2,1]^2+2*A[1,2]^22*A[1,1]^2)*A[2,2]^2+8*A[1,1]*A[1,2]*A[2,1]*A[2,2]+A[2,1]^4+(2*A[1,1]^22*A[1,2]^2)*A[2,1]^2+A[1,2]^4+2*A[1,1]^2*A[1,2]^2+A[1,1]^4)+A[2,2]^2+A[2,1]^2+A[1,2]^2+A[1,1]^2)/SQRT(2),SQRT(SQRT(A[2,2]^4+(2*A[2,1]^2+2*A[1,2]^22*A[1,1]^2)*A[2,2]^2+8*A[1,1]*A[1,2]*A[2,1]*A[2,2]+A[2,1]^4+(2*A[1,1]^22*A[1,2]^2)*A[2,1]^2+A[1,2]^4+2*A[1,1]^2*A[1,2]^2+A[1,1]^4)+A[2,2]^2+A[2,1]^2+A[1,2]^2+A[1,1]^2)/SQRT(2)]
$$ \left\{ {{\sqrt{\sqrt{a^{4}_{2,2}+\left(2\,a^{2}_{2,1}+2\,a^{2}_{1%
,2}2\,a^{2}_{1,1}\right)\,a^{2}_{2,2}+8\,a_{1,1}\,a_{1,2}\,a_{2,1}%
\,a_{2,2}+a^{4}_{2,1}+\left(2\,a^{2}_{1,1}2\,a^{2}_{1,2}\right)\,a%
^{2}_{2,1}+a^{4}_{1,2}+2\,a^{2}_{1,1}\,a^{2}_{1,2}+a^{4}_{1,1}}+a^{2%
}_{2,2}+a^{2}_{2,1}+a^{2}_{1,2}+a^{2}_{1,1}}}\over{\sqrt{2}}},{{%
\sqrt{\sqrt{a^{4}_{2,2}+\left(2\,a^{2}_{2,1}+2\,a^{2}_{1,2}2\,a^{2%
}_{1,1}\right)\,a^{2}_{2,2}+8\,a_{1,1}\,a_{1,2}\,a_{2,1}\,a_{2,2}+a%
^{4}_{2,1}+\left(2\,a^{2}_{1,1}2\,a^{2}_{1,2}\right)\,a^{2}_{2,1}+a%
^{4}_{1,2}+2\,a^{2}_{1,1}\,a^{2}_{1,2}+a^{4}_{1,1}}+a^{2}_{2,2}+a^{2%
}_{2,1}+a^{2}_{1,2}+a^{2}_{1,1}}}\over{\sqrt{2}}}\right\} $$ 

Back to top 


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@ptnnntpreader01.plus.net>,
lesshaste <rcliffor@jesus.ox.ac.uk> 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^24*d))/2;
r2 := d/r1;
h := sqrt(B[1,2]^2+(r1B[1,1])^2);
Q2[1,1] := B[1,2]/h;
Q2[2,2] := Q2[1,1];
Q2[2,1] := (r1B[1,1])/h;
Q2[1,2] := Q2[2,1];
k := sqrt(C[1,2]^2+(r1C[1,1])^2);
Q1[1,1] := C[1,2]/k;
Q1[2,2] := Q1[1,1];
Q1[2,1] := (r1C[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 dividebyzero errors in some degenerate
cases, or inaccurate results in some nearlydegenerate 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 

Back to top 


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@ptnnntpreader01.plus.net>,
lesshaste <rcliffor@jesus.ox.ac.uk> 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^24*d))/2;
r2 := d/r1;
h := sqrt(B[1,2]^2+(r1B[1,1])^2);
Q2[1,1] := B[1,2]/h;
Q2[2,2] := Q2[1,1];
Q2[2,1] := (r1B[1,1])/h;
Q2[1,2] := Q2[2,1];
k := sqrt(C[1,2]^2+(r1C[1,1])^2);
Q1[1,1] := C[1,2]/k;
Q1[2,2] := Q1[1,1];
Q1[2,1] := (r1C[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 dividebyzero errors in some degenerate
cases, or inaccurate results in some nearlydegenerate 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 

Back to top 


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@ptnnntpreader01.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^24*d))/2;
r2 := d/r1;
h := sqrt(B[1,2]^2+(r1B[1,1])^2);
Q2[1,1] := B[1,2]/h;
Q2[2,2] := Q2[1,1];
Q2[2,1] := (r1B[1,1])/h;
Q2[1,2] := Q2[2,1];
k := sqrt(C[1,2]^2+(r1C[1,1])^2);
Q1[1,1] := C[1,2]/k;
Q1[2,2] := Q1[1,1];
Q1[2,1] := (r1C[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 dividebyzero errors in some degenerate
cases, or inaccurate results in some nearlydegenerate 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 

Back to top 


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 

Back to top 


Google


Back to top 



The time now is Mon Dec 10, 2018 9:34 pm  All times are GMT

