필터 지우기
필터 지우기

Element Wise Matrix multiplication issue (.*)

조회 수: 3 (최근 30일)
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy 2023년 9월 17일
답변: Sam Chak 2023년 9월 25일
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
Dyuman Joshi
Dyuman Joshi 2023년 9월 17일
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 2023년 9월 17일
편집: Dyuman Joshi 2023년 9월 17일
@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

댓글을 달려면 로그인하십시오.

채택된 답변

Sam Chak
Sam Chak 2023년 9월 17일
편집: Sam Chak 2023년 9월 18일
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
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy 2023년 9월 18일
편집: Yuvraaj Pasumarthy 2023년 9월 18일
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 2023년 9월 25일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sam Chak
Sam Chak 2023년 9월 25일
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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by