1

I am working with a piece of Matlab where I have:

n = 4;
Mbar = zeros(n,n);
Mbar(1,1) = M;
Mbar(2,2) = Ixx;
Mbar(3,3) = Iyy;
Mbar(4,4) = Izz;

L = zeros(n,n);
L = chol(Mbar)';

An error message said that it didn't like M, Ixx, Iyy, and Izz. So I changed the code to:

syms M Ixx Iyy Izz;
assume(M>0);
assume(Ixx>0);
assume(Iyy>0);
assume(Izz>0);
M = vpa(Mbar(1,1));
Ixx = vpa(Mbar(2,2));
Iyy = vpa(Mbar(3,3));
Izz = vpa(Mbar(4,4));

L = zeros(n,n);
L = chol(Mbar)';

An error message was returned stating that Mbar must be positive definite for the Cholesky decomposition to be performed. Is there a way to define the variables in Mbar such that I am ensured that Mbar is positive definite?

horchler
  • 3,203
Lanae
  • 355

1 Answers1

1

I really have no idea what you are trying to do. All of your code is out of order. I think that this is all that you need, though the result is trivial for a diagonal matrix:

syms M Ixx Iyy Izz;
assume(M>0);
assume(Ixx>0);
assume(Iyy>0);
assume(Izz>0);
Mbar = diag([M Ixx Iyy Izz]);
L = chol(Mbar)'

which returns

L =

[ M^(1/2),         0,         0,         0]
[       0, Ixx^(1/2),         0,         0]
[       0,         0, Iyy^(1/2),         0]
[       0,         0,         0, Izz^(1/2)]

The reason the first case didn't work is because you were using Matlab's default numeric functionality and had not assigned any values to M, Ixx, etc. You got the error in the second case because you didn't create your Mbar matrix other than allocate it as all zeros.

horchler
  • 3,203
  • ~ I will try this. I have no values for M, Ixx, etc. I needed to find L based on Mbar to be used in another piece of code that generates random matrices such that, ultimately, Mr = LGL'. Thanks!! – Lanae Nov 09 '13 at 22:14
  • ~ this error message showed up: Undefined function 'chol' for input arguments of type 'sym'.

    L = chol(Mbar)';

    – Lanae Nov 09 '13 at 22:23
  • What version of Matlab do you have? What does which sym/chol return? Do you get a help result for help sym/chol? – horchler Nov 10 '13 at 17:29
  • ~ figured it out. I did need concrete numbers to use in Matlab. It did not like the symbols. I think I'm using 2010b. It may be newer though. The university gives us copies. At any rate, I used your simplified version with some actual values for the x, y, and z positions of my cuboid. Thanks!! – Lanae Nov 13 '13 at 05:41