Optimizing a function of a given matrix Let us consider the $4\times 4$ symmetric matrix $$A_x=\left(\begin{array}{rrrr} 0 & 1 & 1 & 1 \ 1 & 0 & 2^x & 2^x \ 1 & 2^x & 0 & 2^x \ 1 & 2^x & 2^x & 0 \end{array}\right)$$

Here I need to find $\min { x>0: det(A_x)=0 \, or \, ||A_x^{-1}||=0 } ,$ where by $||M||$ we mean the sum of all entries of the matrix $M.$ I'm looking for a general sage program where my input will be a matrix with entries as functions of an inderminant (like the matrix $A_x$ above) which will give me the unique $x$ corresponding to my matrix. If no such real value exists, it should result as $\infty$ Can anyone help me? Thank you in advance.

edit retag close merge delete

Sort by » oldest newest most voted

One could use Sage to explore the problem.

Define the matrix $A$:

sage: A = matrix(SR, 4, [0, 1, 1, 1, 1, 0, 2^x, 2^x, 1, 2^x, 0, 2^x, 1, 2^x, 2^x, 0])
sage: A
[  0   1   1   1]
[  1   0 2^x 2^x]
[  1 2^x   0 2^x]
[  1 2^x 2^x   0]

Compute its determinant:

sage: det(A)
-3*2^(2*x)

The sum of its entries:

sage: sum(A.list())
6*2^x + 6

Its inverse:

sage: ~A
[-2/3*2^x      1/3      1/3      1/3]
[     1/3 -2/3/2^x  1/3/2^x  1/3/2^x]
[     1/3  1/3/2^x -2/3/2^x  1/3/2^x]
[     1/3  1/3/2^x  1/3/2^x -2/3/2^x]

The sum of the entries of its inverse:

sage: sum((~A).list())
-2/3*2^x + 2

Now solve $\det(A) = 0$ and $\lVert A^{-1} \rVert = 0$, extract positive solutions, take the minimum, and compute a numerical approximation.

sage: S = solve(det(A) == 0, x); S
[]
sage: T = solve(sum((~A).list()) == 0, x); T
[x == (log(6) - log(2))/log(2)]
sage: min([e.rhs() for e in S + T if e.rhs() > 0]).n()
1.58496250072116

This can all be put in a function which, given a matrix A as above, returns this minimum positive solution.

more

Actually, I was stuck at this step. I tried the code "solve" to solve the two systems, but I don't get numerical value from this. Again I tried "find_root" code with the interval but one of the systems (First one) does not have a solution, and so it gives a long list of errors. Therefore I cannot evaluate the minimum of all solutions (min() doesn't work). For this particular matrix, I can find it by direct calculation. But what I need a general method to get my required (numerical value) whenever I input a matrix as a function of $x$. I need something like this

X=det(A); Y=sum((~A).list()); S=solve([X,x>0],x); T=solve([Y,x>0],x); min(S+T)

This doesn't give me numerical value. Note the last step, I want sage to calculate the minimum value of the ...(more)

Thank you for your solution. It works with that particular matrix. But it doesn't work for all matrices.

For example consider $$A=\left(\begin{array}{rrrrr} 0 & 2^{x} & 1 & 1 & 1 \ 2^{x} & 0 & 1 & 1 & 1 \ 1 & 1 & 0 & 2^{x} & 2^{x} \ 1 & 1 & 2^{x} & 0 & 2^{x} \ 1 & 1 & 2^{x} & 2^{x} & 0 \end{array}\right)$$

or

$$A=\left(\begin{array}{rrrr} 0 & 1 & 2^{x} & 1 \ 1 & 0 & 1 & 2^{x} \ 2^{x} & 1 & 0 & 1 \ 1 & 2^{x} & 1 & 0 \end{array}\right)$$

Here I get an error "cannot evaluate symbolic expression numerically"

Note: For all my matrices, it is known that the solution is at most equal to 2. So if something like min(find_root(X,0,2)+find_root(Y,0,2)) could be used, that is also enough for me.