using a matrix in a calculation

i am trying to compute the equation:
vr = (v0*r)/(sqrt(r^2+(w*l-1/(w*c))^2));
where everything in the equation is a scalar and w is a matrix. However when I run this code I get an error that states:
Error using /
Matrix dimensions must agree.
I dont understand how the dimensions wouldn't agree in this situation.

답변 (2개)

Akira Agata
Akira Agata 2023년 5월 1일

1 개 추천

To do an element-wise calculation of an equation to a matrix, you should add dot (.) just before operator, like:
vr = (v0*r)./(sqrt(r^2+(w*l-1./(w*c))^2));

댓글 수: 2

joseph
joseph 2023년 5월 1일
This worked, thank you so much
Let me correct one typo:
vr = (v0*r)./(sqrt(r^2+(w*l-1./(w*c)).^2)); % need dot (.) before ^ operator, too

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

Matt J
Matt J 2023년 5월 1일

0 개 추천

Use element-wise operators .*, ./, and .^

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2023년 5월 1일

댓글:

2023년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by