Error : Undefined variable

8 次查看(过去 30 天)
Error displayed:
Undefined function or variable '1'.
Error in cs2 (line 30)
I am not able to understand why am I getting that error, please guide as soon as possible. Thanks a lot.
%(ch11p3) Example 11.3’ % Display label.
pos=input ("Type %OS "); % Input desired percent overshoot.
Tp=input("Type peak time "); % Input desired peak time.
Kv=input("Type value of Kv"); % Input Kv.
numg=[100]; % Define numerator of G(s).
deng=poly ([0 -36 -100]); % Define denominator of G(s).
G=tf(numg,deng); % Create G(s).
s=tf([1 0], 1); % Create transfer function,’s’.
sG=s*G; % Create sG(s).
sG=minreal(sG); % Cancel common factors.
K=dcgain(Kv/sG); % Solve for K.
disp("G(s)") % Display label.
G=zpk (K*G) % Put K into G (s), convert to
% factored form, and display.
% Calculate required damping
% ratio.
% Calculate required phase margin.
wn=pi/ (Tp*sqrt(l-z^2)); % Calculate required natural
% frequency.
% Determine required bandwidth.
w=0.01:0.5:1000; % Set range of frequency from 0.01
% to 1000 in steps of 0.5
[M,P]=bode(G,w); % Get Bode data.
[Gm,Pm,Wcg,Wcp]=margin(G); % Find current phase margin.
% Calculate required phase margin.
Pmreqc=Pmreq+10; % Add a correction factor of 10
% degrees.
Pc=Pmreqc-Pm; % Calculate phase contribution
% required from lead compensator.
% Design lead compensator
% Find compensator beta.
magpc=1/sqrt(beta); % Find compensator peak magnitude.
for k=1: 1: length(M); % Find frequency at which
% uncompensated system has a
% magnitude of 1/magpc.
% This frequency will be the new
% phase margin frequency.
if M(k)-(1/magpc) <=0 ;% Look for peak magnitude.
wmax=w(k); % This is the frequency at the
% peak magnitude.
break % Stop the loop,
end % End if.
end % End for.
% Calculate lead compensator zero, pole, and gain.
zc=wmax*sqrt(beta); % Calculate the lead compensator’s
% low break frequency.
pc=zc/beta; % Calculate the lead compensator’s
% high break frequency.
Kc=1/beta; % Calculate the lead compensator’s
disp("Gc(s)"); % Display label.
Gc=tf (Kc*[1 zc],[1 pc]); % Create Gc(s).
Gc=zpk(Gc) % Convert Gc (s) to factored form
% and display.
disp("Ge(s)=G(s)Gc(s)"); % Display label.
Ge=G*Gc % Form Ge(s)=Gc(s)G(s).
sGe=s*Ge; % Create sGe(s).
sGe=minreal (sGe); % Cancel common factors.
Kv=dcgain(sGe) % Calculate Kv.
T=feedback(Ge,1); % Find T(s).
step(T) % Generate closed-loop, lead-
% compensated step response.
title("Lead-Compensated Step Response")
% Add title to lead-compensated
% step response.


Stephen23 2020-5-24
编辑:Stephen23 2020-5-24
You incorrectly transcribed the error message: the actual character shown is lower-case L, i.e. l, not a 1 like you showed. To avoid this mistake it is much better if you simply copy-and-paste the entire error message.
The reason is very simple: you refer to a function or variable l many times, but it is never defined. Here is the first instance:
% ^ lower-case L not defined in your code.
After that line it occurs repeatedly, so perhaps you just need to assign some value to l at the start of your code.

更多回答(0 个)


Help CenterFile Exchange 中查找有关 Floating-Point to Fixed-Point Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by