# using a matrix in a calculation

3 vues (au cours des 30 derniers jours)
joseph le 1 Mai 2023
Commenté : Akira Agata le 1 Mai 2023
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.
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Akira Agata le 1 Mai 2023
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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Akira Agata le 1 Mai 2023
Let me correct one typo:
vr = (v0*r)./(sqrt(r^2+(w*l-1./(w*c)).^2)); % need dot (.) before ^ operator, too

Connectez-vous pour commenter.

Matt J le 1 Mai 2023
Use element-wise operators .*, ./, and .^
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Operators and Elementary Operations 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!