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.

Risposte (2)

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 Commenti

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

Accedi per commentare.

Matt J
Matt J il 1 Mag 2023

0 voti

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

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Richiesto:

il 1 Mag 2023

Commentato:

il 1 Mag 2023

Community Treasure Hunt

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

Start Hunting!

Translated by