Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Been working in this matlab program, but cant figure why Im getting this error :

ID: 2082637 • Letter: B

Question

Been working in this matlab program, but cant figure why Im getting this error :

Undefined function or variable 'Vt'.

Error in CLEANED_MATLAB_SCRIPT (line 70)
y1 = Vt;

//////////////////////////////////////////////////////////

%Prompt user for RLC Variables
funcprot = 0;
disp('Series RLC Circuit: Step Response Calculator');
R=input('Enter the resistor value: ');
L=input('Enter the decimal value of the inductor: ');
Lres=input('Enter the value of your inductor resistance. (If unknown, type "0": ');
%IF statement for if user input = 0 to give default value for Lres
if Lres==0
Lres=150;
disp('Inductor resistance default value: 150.');
end
C=input('Enter the decimal value of the capacitor: ');

%Initial variables
V0 = 0;
Vf = 2;
time = linspace (0,0.0025,10);

%Formulas for Neper, Resonant Radiant, and Damped Radian frequencies, and
%characteristic roots
Rtot = R + Lres;
alpha= R/(2*L);
omega0= 1/sqrt(L*C);
omegaD= sqrt((omega0^2)-(alpha^2));
s1= -alpha + sqrt((alpha^2)-(omega0^2));
s2= -alpha - sqrt((alpha^2)-(omega0^2));

%Inform user of 2V power source, display frequencies, roots
disp ('Using a 2V power source, the circuit values are: ');
disp('Alpha = '); disp(alpha)
disp ('omega_naught = '); disp(omega0);
disp ('omega_d = '); disp(omegaD)
disp('s1 = '); disp(s1)
disp('s2 = '); disp(s2)

%IF STATEMENTS FOR CIRCUIT RESPONSE:

%If statement to determine if overdamped
if(alpha^2 > omega0^2)
disp('Circuit has an overdamped response.')
end

%If statement to determine if critically damped
if(omega0^2 == alpha^2)
disp('Circuit has a critically damped response.')
end

%If statement to determine if underdamped response
if(alpha^2 < omega0^2)
disp ('Circuit has an underdamped response.')
  
%Formulas for Underdamped Natural Response
B1N = V0;
B2N = (alpha*B1N)/omegaD;
Vt = (B1N * (cos(omegaD*time)) + B2N *(sin(omegaD*time))) .*exp(-alpha*time);

%Formulas for Underdamped Step Response
B1S = V0 - Vf;
B2S= (alpha*B1S)/omegaD + Vf;
udStep = (B1S * (cos(omegaD*time)) + B2S *(sin(omegaD*time))) .*exp(-alpha*time)+Vf;
  
%Additional information for user: display B1, B2, B'1, B'2 values
disp('B1 Natural = '); disp (B1N);
disp('B2 Natural = '); disp (B2N);
disp('B1 Step = '); disp (B1S);
disp('B2 Step = '); disp (B2S);   
end

%Graph plotting for Natural & Step Responses
y1 = Vt;% here is the error but cant figure out what its wrong with it !
y2 = udStep;
figure
plot (time, Vt, 'r*', time, udStep, 'b--o')
title('Graph for Underdamped Step & Natural Response')
xlabel('Time (s)')
ylabel('Voltage across capacitor (V)')
legend('Natural Response', 'Step Response')

Explanation / Answer

The variable Vt is defined only for the case when 'Circuit has an underdamped response'. Therefore when either of the cases 'Circuit has an overdamped response' or 'Circuit has a critically damped response' occurs, Vt is not defined. Hence ur getting the errror 'Vt is not defined'. Define Vt for the cases 'Circuit has an overdamped response' and 'Circuit has a critically damped response' , ur problem shold be solved.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote