# Simple Matlab Problem [closed]

I just started working with Matlab last week, so I'm very new. After searching for a while, I realized that I don't know how to fix a Matlab script that I'm working with. The problem is given below.

z(jω) = R + (jwl)/(1−(w^2)LC)
If L = 1 mH, C = 10 μF, and R = 100 Ω, plot the magnitude of the input
impedance for w = 10, 100, 1000, 1.0e04, and 1.0e05 rads/s.


This is all that I felt was necessary to solve this introductory problem:

L = 0.001;
C = 0.00001;
R = 100;

z = @(w) (abs(R+(1j*w*L)/(1-(w.^2)*L*C)));
W = [10 100 1000 10000 100000];
out = z(W);
plot(W, out)
ylabel('z (ohms)')


but for some reason, 'out' is always a single number instead of a 1x5 matrix like W is. I have messed with it for a while now and tried to find out what's going on, but haven't gotten anywhere. Thanks in advance everyone.

• have you tried breaking down your expression in interactive mode and seeing what pieces you can get your 1x5 vector out of? – Daniel Apr 6 '16 at 2:48
• I'm voting to close this question as off-topic because it's a general Matlab programming question that would be a better fit on Stack Overflow. – PeterJ Apr 6 '16 at 5:25

1. You should be using ./ for by element, rather than matrix divide.

2. There's really no need for a function handle here.

I would write it like this (NOTE: no Matlab on this computer, so this is untested):

w = [10 100 1000 10000 100000];
z = (R+(1j*w*L))./(1-(w.^2)*L*C);

plot(w, abs(z))