Question
please help to correct my code. How to make it run multiple times for different values of a variable iL0 and v(0) here is the
please help to correct my code. How to make it run multiple times for different values of a variable iL0 and v(0)
here is the code:
clear
clc
% Initial parameters
R=100; L=1e-3; C=1e-6;
v0=[6, 6, 6];
iL0=[0.25, -0.25, 0];
% Initial arrays
v=zeros(501,1);
system_parameter=(2*R*C)^2-(L*C);
fo=fopen('output.txt','w');
fprintf(fo, 'system_parameter=%10.2e ',system_parameter);
if system_parameter
% system is overdamped
% v0=A+B or B=v0-A
% A=1/(2*sqrt(1/(2*R*C)^2-1/(L*C))*
% (-v0/(2RC)-iL0/C+v0*sqrt(1/(2*R*C)^2-1/(L*C))
num=v0*sqrt(1/(2*R*C)^2-1/(L*C))-v0/(2*R*C)-iL0/C;
den=2*sqrt(1/(2*R*C)^2-1/(L*C));
A=num/den;
B=v0-A;
D=0;
fprintf(fo, 'System is overdamped, A=%8.4f B=%8.4f ',A,B);
end
if system_parameter>0.0
% system is underdamped
A=v0;
num = -v0/(R*C)-1/C*iL0+v0/(2*R*C);
den = sqrt(1/(L*C)-1/(2*R*C)^2);
B=num/den;
D=1;
fprintf(fo,'Sys is underdamped,A=%8.4f B=%8.4f ',A,B);
end
% Creating table
dt=1.0e-6;
for i=1:1501
tm(i)=(i-1)*dt;
t=tm(i);
if D==0; %system is overdamped
arg1=1/(2*R*C);
arg2=sqrt(1/(2*R*C)^2-1/(L*C));
v(i)=exp(-arg1*t)*(A*exp(arg2*t)+B*exp(-arg2*t));
end
if D==1; %system is underdamped
arg1=1/(2*R*C);
arg2=sqrt(1/(L*C)-1/(2*R*C)^2);
v(i)=exp(-arg1*t)*(A*cos(arg2*t)+B*sin(arg2*t));
end
end
fprintf(fo,' t(s)x1.0e+4 v1(volts) v2(volts) v3(volts) ');
fprintf(fo, '------------------------------------------------------ ')
t2=tm*1.0e+4;
for i=1:10:501
t(i)=tm(i)*1.0e+6;
fprintf(fo,'%10.2f %10.2f ',t2(i),v(i));
end
fclose(fo);
figure(1)
clf
plot(tm,v)
xlabel('time(s)')
ylabel('v')
grid
title('v (volts) vs time(s)'),
legend('iL=0.25');
Given the following component values in the parallel RLC circuit described in section 217 R=100 , L=1mH C-1 F and the following initial conditions, determine the coefficients A and B for the following 3 cases i(0)-0.25 A. vc (0)-6V (Hint: convert (0) to v"(0) with Equation (2.7)) ii 0-0.25A, vc(0)-6V iii. iL (0) = 0, -(0)=6V For each case, determine an expression for A and B in terms of R, L, C, vc (0) and i (0) and write a MATLAB program that will: a) Determine v(t) for os, 500 sec in steps of 1 sec. b) Print out a table of v vs. t every 10 usec. c) Plot v vs. t for all three cases on the same graph. Label each curve with the value of i, (0)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started