Re: Re: Problem with Minimize function

*To*: mathgroup at smc.vnet.net*Subject*: [mg71940] Re: [mg71925] Re: Problem with Minimize function*From*: Ray Koopman <koopman at sfu.ca>*Date*: Tue, 5 Dec 2006 06:04:38 -0500 (EST)*Reply-to*: koopman at sfu.ca

On Mon, 04 Dec 2006 09:01:39 -0600 danl at wolfram.com wrote: > Ray Koopman wrote: >> amitsoni.1984 at gmail.com wrote: >> >>> I am using following program: >>> A = {{2, 4, 5}, {6, 7, 3}, {3, 7, 3}} >>> Minimize[-Abs[ >>> A[[1, 1]]*q11 + A[[1, 2]]*q21 + A[[1, 3]]*q31 + A[[2, 1]]*q12 + >>> A[[2, 2]]*q22 + A[[2, 3]]*q32 + A[[3, 1]]*q13 + A[[3, 2]]*q23 + >>> A[[3, 3]]*q33], >>> q11^2 + q12^2 + q13^2 == 1 && q11*q21 + q12*q22 + q13*q23 == 0 && >>> q11*q31 + q12*q32 + q13*q33 == 0 && q21^2 + q22^2 + q23^2 == 1 && >>> q21*q31 + q22*q32 + q23*q33 == 0 && q31^2 + q32^2 + q33^2 == 1, >>> {q11, q12, q13, q21, q22, q23, q31, q32, q33}] >>> >>> I tried using NMinimize function and it worked fine with it. But I >>> could not figure out what is the difference between these two >>> functions(Minimize and NMinimize) from their definitions on the >>> mathematica website. >>> >>> Thanks >>> Amit >> >> >> In matrix terms, you're maximizing Tr[A.Q], subject to >> Q.Transpose@Q == I. The -Abs wrapper in an unnecessary complication >> that makes -Q a solution if Q is a solution. >> You want Q = Transpose[First at #.Last@#]&[SingluarValueDecomposition@A] > > Seems a bit off. > > A = {{2,4,5}, {6,7,3}, {3,7,3}}; > qmat = Array[q, {3,3}]; > qvars = Flatten[qmat]; > obj = Tr[A.qmat]; > > In[16]:= InputForm[{nmax,vals} = NMaximize[{obj, constraints}, qvars] ] > Out[16]//InputForm= > {18.604296495558675, {q[1, 1] -> -0.012055111538764663, > q[1, 2] -> 0.9577478811414728, q[1, 3] -> -0.287356348495888, > q[2, 1] -> 0.02333138205014669, q[2, 2] -> 0.2875684102368304, > q[2, 3] -> 0.9574758780624395, q[3, 1] -> 0.9996551012738198, > q[3, 2] -> 0.004838058445076696, q[3, 3] -> -0.02581225024159173}} > > In[17]:= InputForm[Q = > Transpose[First at #.Last@#]&[SingularValueDecomposition@N[A]]] > Out[17]//InputForm= > {{-0.3105080321836895, 0.9492864199199935, -0.04939691189633988}, > {-0.15290065052613921, 0.0014106929655585687, 0.988240558272145}, > {0.9381930254580325, 0.3144094510361273, 0.14470847964464584}} > > In[18]:= max1 = obj /. vals > Out[18]= 18.6043 > > In[19]:= max2 = Tr[A.Q] > Out[19]= 17.3108 > > After playing with a bunch of permutations of this, I think this next > one gives the right result. > > In[34]:= InputForm[Q2 = > (Last at #.Transpose[First@#])&[SingularValueDecomposition@N[A]]] > Out[34]//InputForm= > {{-0.01205441069899682, 0.9577474301383769, -0.2873578800834159}, > {0.023331710012777895, 0.2875699237830144, 0.9574754149550322}, > {0.9996551017678946, 0.004837251158067629, -0.02581237127143146}} > > In[35]:= max2 = Tr[A.Q2] > Out[35]= 18.6043 > > Daniel You're right. If the svd of A is UDV' then Q = VU'. I was treating the last result from SingularValueDecomposition as if it were V', when in fact it is V. (I also wrote "I" where I should have written IdentityMatrix@3.)