Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm facing the following problem and would very much like you help. Thanks is advance!

I have defined the following 4x4 matrix: \begin{equation} S=\left( \begin{array}{cccc} \frac{1}{r^2} & 1 & 1 & t\sqrt{x}\\ 1 & \frac{1}{t^2} & 1 & \frac{\sqrt{x}}{t}\\ 1 & 1 & 1 & \sqrt{q} \\ t\sqrt{x} & \frac{\sqrt{x}}{t} & \sqrt{q} & 1 \end{array} \right). \end{equation} where $(t,r)$ are two parameters (which I can choose arbitrarily to be any value in the segment $(0,1]$) and $(x,q)$ are the variables (each over the domain $[0,1]$).

Now, for a fixed pair of $(r,t)$ I want to plot a region of $(x,q)$ over which the matrix $S$ is positive semi-definite (I want it to be a valid covariance matrix). The thing is that when I try to use the Manipulate function (manipulation on $(r,t)\in(0,1]^2$), and plotting the region of $(x,t)$, nothing shows. Namely, Iv'e written the following:

S={{1/r^2, 1, 1, t Sqrt[x]}, {1, 1/t^2, 1, Sqrt[x]/t}, 
   {1, 1, 1, Sqrt[q]}, {t Sqrt[x], Sqrt[x]/t, Sqrt[q], 1}};

             {x, 0, 1}, {q, 0, 1}], {r, 0, 1}, {t, 0, 1}]

and I get an empty graph no matter what values I set for $(r,t)$. You might say that maybe this matrix is never positive semi-definite, but the strange this is that if I manually input numerical values to $(r,t)$ and plot the region, everything works fine.

I really need to manipulate over all possible parameter value of $(r,t)$. What is wrong here and how can I fix it?

Moreover, is it possible for Mathematica to parametrically find a local minima of a certain function (of the variable $q$ where $(r,t,x)$ serve as parameters) subject to the constraint that the above matrix must be positive semi-definite? If so, it would very much help me to know how to formalize such a command.

share|improve this question
Same problem as in… and many others. – Sjoerd C. de Vries Jul 16 '13 at 22:47
up vote 5 down vote accepted

Try to define your matrix as a function of $(x,q,r,t)$ variables

S[x_, q_, r_, t_] := {{1/r^2, 1, 1, t Sqrt[x]}, {1, 1/t^2, 1, Sqrt[x]/t}, {1, 1, 1, Sqrt[q]}, {t Sqrt[x], Sqrt[x]/t, Sqrt[q], 1}};

Then Manipulate does what you want

  PositiveDefiniteMatrixQ@S[x, q, r, t], {x, 0, 1}, {q, 0, 1}],
   {{r, 1/2}, 0, 1}, {{t, 1/2}, 0, 1}]

enter image description here

share|improve this answer
Great! thank you very much. How about the minimization problem? Is it possible to do what I want? – Ziv Goldfeld Jul 16 '13 at 9:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.