FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Forum index » Science and Technology » Math » Symbolic
simple formula for svd of 2 by 2 array
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
Richard J. Fateman
science forum addict


Joined: 04 May 2005
Posts: 81

PostPosted: Tue Jun 13, 2006 7:55 pm    Post subject: Re: simple formula for svd of 2 by 2 array Reply with quote

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]^2-2*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]^2-2*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]^2-2*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]^2-2*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

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

lesshaste wrote:
Quote:
Robert Israel wrote:
In article <448de77e$0$69392$ed2619ec@ptn-nntp-reader01.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^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
Back to top
lesshaste
science forum beginner


Joined: 12 Jun 2006
Posts: 2

PostPosted: Tue Jun 13, 2006 8:00 am    Post subject: Re: simple formula for svd of 2 by 2 array Reply with quote

Robert Israel wrote:
Quote:
In article <448de77e$0$69392$ed2619ec@ptn-nntp-reader01.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^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
Back to top
Robert B. Israel
science forum Guru


Joined: 24 Mar 2005
Posts: 2151

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

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
Back to top
lesshaste
science forum beginner


Joined: 12 Jun 2006
Posts: 2

PostPosted: Mon Jun 12, 2006 10:15 pm    Post subject: simple formula for svd of 2 by 2 array Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Mon Aug 21, 2017 1:57 pm | All times are GMT
Forum index » Science and Technology » Math » Symbolic
Jump to:  

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

Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Electronics forum |  Medicine forum |  Unix/Linux blog |  Unix/Linux documentation |  Unix/Linux forums  |  send newsletters
 


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0230s ][ Queries: 20 (0.0043s) ][ GZIP on - Debug on ]