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

error using .* matrix dimensions must agree

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

Best Answer

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.