Element Wise Matrix multiplication issue (.*)

4 visualizaciones (últimos 30 días)
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy el 17 de Sept. de 2023
Respondida: Sam Chak el 25 de Sept. de 2023
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 comentarios
Dyuman Joshi
Dyuman Joshi el 17 de Sept. de 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
Dyuman Joshi el 17 de Sept. de 2023
Editada: Dyuman Joshi el 17 de Sept. de 2023
@Yuvraaj Pasumarthy, zeta and r are not compatible for matrix multiplication or element-wise multiplication.
zeta= 0.1:0.01:1;
size(zeta)
ans = 1×2
1 91
r= 0.01:100;
size(r)
ans = 1×2
1 100

Iniciar sesión para comentar.

Respuesta aceptada

Sam Chak
Sam Chak el 17 de Sept. de 2023
Editada: Sam Chak el 18 de Sept. de 2023
Update: With the values of zeta, beta, and mu provided, you can plot something. You can try experimenting yourself.
% Assigning parameters
zeta = [0.05, 0.1, 0.3, 0.5, 1];
beta = 0.5;
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(zeta)
M = sqrt((1 + 4*(zeta(i)^2)*(r.^2)).*(1 - (beta^2)*(r.^2)).^2)./sqrt((1 - ((1 + mu)*beta^2 + 1)*r.^2 + (beta^2)*(r.^4)).^2 + 4*(zeta(i)^2)*(r.^2).*(1 - (1 + mu)*(beta^2)*(r.^2)).^2);
txt = ['\zeta = ', num2str(zeta(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}')
legend show
  9 comentarios
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy el 18 de Sept. de 2023
Editada: Yuvraaj Pasumarthy el 18 de Sept. de 2023
Thank you so much for the updating naming @Sam Chak, I had a doubt. If I want graphs for different values of mu and beta, which in the code are variables that take only one constant value, how do I change that?
Sam Chak
Sam Chak el 25 de Sept. de 2023
You are welcome! You can change the values for beta β and mu μ on Lines 3 and 4 as indicated below:
% Assigning parameters % <-- Line 1
zeta = [0.05, 0.1, 0.3, 0.5, 1]; % <-- Line 2
beta = 0.5; % <-- Line 3
mu = 2; % <-- Line 4
r = logspace(-2, 2, 4001); % <-- Line 5

Iniciar sesión para comentar.

Más respuestas (1)

Sam Chak
Sam Chak el 25 de Sept. de 2023
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

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by