I have two same errors every time i paste a code to check
121 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This is my task and here is code:% Load the x-y-z positions into the variable R
load datafile.mat
m = 1.2; % particle mass in kg
% Find the center of mass location in a row vector rcm
rcm = mean(R);
% Find the moment of inertia matrix I, a 3-by-3 matrix
Ixx = sum(m*(R(:,2).^2+R(:,3).^2));
Iyy = sum(m*(R(:,1).^2 + R(:,3).^2));
Izz = sum(m*(R(:,1).^2 + R(:,2).^2));
Ixy = -sum(m * R(:,1) .* R(:,2));
Ixz = -sum(m * R(:,1) .* R(:,3));
Iyz = -sum(m * R(:,2) .*R(:,3));
% Composite main inertia matrix I
I = [ Ixx, Ixy, Ixz;
Ixy, Iyy, Iyz;
Ixz, Iyz, Izz ];
% Find the principal moment of inertia
[~,II] = eig(I);
and the errors are

I tried many different methods to solve this but non of them worked :/, thanks for any help
Respuestas (2)
sneha
el 11 de Nov. de 2025 a las 10:44
Editada: sneha
el 11 de Nov. de 2025 a las 10:46
Hello,
Code looks almost correct, but the issue looks like with the definition of the moment of inertia matrix. Specifically, you did not subtract the centre of mass from each position before calculating the inertia tensor. The inertia tensor must be calculated about the centre of mass, not the origin.
You used R(:,1), R(:,2), and R(:,3) directly, which are positions relative to the origin.
Try using positions relative to the center of mass: R – rcm
Replace every instance of R(:,...) in your inertia tensor calculation with Rcm(:,...).
To know more about this topic, you can refer to:
Thanks
6 comentarios
Jakub
el 12 de Nov. de 2025 a las 16:20
2 comentarios
Dyuman Joshi
el 12 de Nov. de 2025 a las 16:35
Ixy = Izz;
Ixz = Iyy;
Iyz = Ixx;
This doesn't make sense at all.
I'd ask for a clarification from your teacher regarding this.
And it seems you had to do some rounding (and sorting as well!).
dpb
el 12 de Nov. de 2025 a las 17:40
Agree w/ @Dyuman Joshi -- the product of intertia terms in the intertia tensor are products, not the same as the moments around the major axes. I think your original solution is correct and this is the wrong answer given what we know here.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


