I have two same errors every time i paste a code to check
113 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
Risposte (2)
sneha
il 11 Nov 2025 alle 10:44
Modificato: sneha
il 11 Nov 2025 alle 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 Commenti
Jakub
circa 15 ore fa
2 Commenti
Dyuman Joshi
circa 15 ore fa
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
circa 14 ore fa
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.
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


