Element Wise Matrix multiplication issue (.*)
Mostra commenti meno recenti
EDIT: Extremely sorry about not providing the values, still very new to MATLAB and its community
B=0.5
u=2
zeta= 0.1 to 1 with an increment of 0.01
r= 0.01 to 100 with no specific increments
M=sqrt((square(1-B^2.*(r.^2))*(1+4.*((zeta*r).^2)))/square(1-((((1+u)*B^2)+1).*(r.^2))+(B^2.*(r.^4)))+4*((zeta*r).^2)*square(1-(1+u)*(B^2.*(r.^2))));
ERROR:
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each
element of the matrix individually, use TIMES (.*) for elementwise multiplication.
2 Commenti
Dyuman Joshi
il 17 Set 2023
Please provide the variables used to define M.
I suspect the error occurs because you are trying to multiply two same sized vectors (zeta and r)
Dyuman Joshi
il 17 Set 2023
Modificato: Dyuman Joshi
il 17 Set 2023
@Yuvraaj Pasumarthy, zeta and r are not compatible for matrix multiplication or element-wise multiplication.
zeta= 0.1:0.01:1;
size(zeta)
r= 0.01:100;
size(r)
Risposta accettata
Più risposte (1)
If you want to examine the effects of varying the beta values while keeping zeta and mu fixed, the structure of the code remains the same; however, you'll loop around beta instead of zeta.
% Assigning parameters
zeta = 0.5;
beta = [0.1, 0.3, 0.5, 0.7, 0.9];
mu = 2;
r = logspace(-2, 2, 4001);
% Setup a repetitive looping task using the for-loop method
% the task is to generate logy-logx plot 5 times, as numel(zeta) = 5
for i = 1:numel(beta)
M = sqrt((1 + 4*(zeta^2)*(r.^2)).*(1 - (beta(i)^2)*(r.^2)).^2)./sqrt((1 - ((1 + mu)*beta(i)^2 + 1)*r.^2 + (beta(i)^2)*(r.^4)).^2 + 4*(zeta^2)*(r.^2).*(1 - (1 + mu)*(beta(i)^2)*(r.^2)).^2);
txt = ['\beta = ', num2str(beta(i))]; % for legend purposes
loglog(r, M, 'DisplayName', txt)
hold on % retain the current plot window so that next graph can be plotted
end
% Labelling stuffs
grid on % toggle grid on
hold off
ylim([1e-4 1e2]) % set y-axis limit for display purposes (same as your image)
xlabel('Frequency ratio, r')
ylabel('Vibration transmissibility, F_{2}/F_{0}')
title('Variation of \beta while keeping \zeta and \mu fixed')
legend show
Categorie
Scopri di più su Entering Commands in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


