Matrix Dimensions Must Agree
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andrew Hawkins
le 25 Oct 2017
Réponse apportée : Steven Lord
le 25 Oct 2017
I have written the code shown below but I'm getting problems with matrix dimension errors, even though all my matrices are the same size, I have also tried using the transpose of Wn to get around the problem but nothing seems to fix it, could anyone spot where the error is?
clc
clear all
rho = 7800; %kg/m^3
b = 67*10^-3;
h = 67*10^-3;
A = b*h; %m^2
E = 200*10^9; %Pa
I = (b*h^3)/12;
L = 1; %m
F0 = 100; %N
Omega = 10; %Hz
x = 0.5; %m - Distance to midspan from the end of the beam
t = linspace(0,20,5); n = [1,3,5,7,9];
Wn = zeros(length(n),1);
for i = 1:length(n)
Wn(i) = (n(i).^2.*pi.^2./L.^2).*sqrt(E*I/rho*A);
v(i) = (((-1).^(n(i)-1)/2)/(Wn.^2-Omega^2))*sin(n(i)*pi*x/L)*(sin(Omega*t)-(Omega/transpose(Wn))*sin(Wn.*t))
end
0 commentaires
Réponse acceptée
Steven Lord
le 25 Oct 2017
You believe all your matrices to be compatible sizes, but from the fact that you receive an error they don't appear to be compatible. One way to check this is to set an error breakpoint and run your code. When or if MATLAB stops on a particular line due to an error, look at the sizes of the arrays you're using on the line where the error occurred. You can use the Workspace component of the Desktop, the whos function, or hovering over the variable name in the file while the Editor has focus to see the sizes of the variables.
Once you've identified the array that is incompatibly sized, set breakpoints on earlier lines where that array is created or manipulated and rerun your code to determine when it becomes incompatibly sized.
In this case I happened to notice something, and I think I see where the problem occurs. Look at the line inside your loop where you compute v(i). What is the size of v(i) compared to the size of Wn [note I didn't say Wn(i)]?
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!