Message Boards Message Boards

0
|
4046 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Question on the Covariance function in Mathematica

Posted 11 years ago
Hi, I am trying use the covariance function in the mathematica using the following command:
Covariance[MatrixForm[Table[u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5}]]]
with the error message "Covariance::shlen: The argument (<<1>>) should have at least two elements."   So I tried the following command:
Covariance[
MatrixForm[Table[u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5}]],
MatrixForm[Table[u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5}]]]
 Then I get the following error :
Covariance::vctmat: The arguments to Covariance are not a pair of vectors or a pair of matrices of equal length.   
So I tried the transpose function on one of the matrix like:
Covariance[
MatrixForm[Table[u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5}]],
Transpose[
  MatrixForm[Table[u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5}]]]]
but it gave me the same error and the problem is not resolved at all..If I am trying to get the covariance expression in the most simplified form of this
{u[i, t] - u[i, t - 1], {i, 1, 10}, {t, 1, 5} } how can I do this..? I would greatly appreciate if anyone could help me out with this critical problem for me.. either on this forum and/or through my email.
POSTED BY: Woo Young Kang
3 Replies
Posted 11 years ago
Thank you very much! I eventually resoved the problem.  Thanks a lot!                                                                             
POSTED BY: Woo Young Kang
Posted 11 years ago
MatrixForm is a wrapper for printing. MatrixForm applied to m has Head MatrixForm so is not seen as a vector or matrix. So eliminate it in the arguments -- if you want to see the result formatted as a matrix use it afterwords.

In the code below I reduced the size of the matrices for brevity, and assumed coefficients Real in the display of the result:
cv = Covariance[Table[u[i, t] - u[i, t - 1], {i, 1, 2}, {t, 1, 2}],
   Table[u[i, t] - u[i, t - 1], {i, 1, 2}, {t, 1, 2}]];

MatrixForm[Simplify[cv, Element[u[_, _], Reals]]]
Best,
David
POSTED BY: David Keith
Sorry. We are very reluctant to have people's email addresses in posts.

For suggestions on formatting posts, please see http://community.wolfram.com/groups/-/m/t/151347
POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract