Error using / Matrix dimensions must agree. (tried using .* and ./)

Hi,
i am getting stuck with this error
Error using / Matrix dimensions must agree.
Error in Problem_2_3 (line 98)
s=(-1/(r*2*c))+sqrt((1/(2*r.*c)).^2-(1/(l*c)))
Here is my code
%%
%(b)
r=[100:100:1000] %ohms
c=1e-06; %farads
l=0.64; %henrys
s=(-1/(r*2*c))+sqrt((1/(2*r.*c)).^2-(1/(l*c)))
First_result= -s
Second_result= +s

 采纳的回答

You need to vectorise the division, using ./ instead of /.
This works:
r=[100:100:1000] %ohms
c=1e-06; %farads
l=0.64; %henrys
s=(-1./(r*2*c))+sqrt((1./(2*r.*c)).^2-(1/(l*c)))
First_result= -s
Second_result= +s
See the documentation on Array vs. Matrix Operations (link) for a relevant discussion.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Navigation Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by