5 views

Uploaded by Saurabh Shukla

- AC_Circuits_LAB.pdf
- Ch07_Std
- Transient1 Rl Rc
- Fundamentals of Switching Phenomenon
- Charging & Discharging of Capacitor
- Transient
- Class 6
- 2008physics1 Web Copyrgt
- 27102B473JO0(capacitor)
- EC303
- transient
- Phasor Method of Solving Circuits
- Wave Shaping Circuits
- Observations
- Transient Response
- Part Test I
- BLR CX Short Manual
- Edexcel Physics Experiment Sheets
- qp-nov_2010-4-1-eee-ehvact.pdf
- ee-spx30csm2162.pdf

You are on page 1of 4

Use Matlab to plot the capacitor voltage and current for the circuit shown in Figure E2-1

below.

Figure E2-1

An RC circuit with a step input.

We assume that the capacitor is completely discharged for t < 0. When the switch closes,

the voltage across the capacitor is given by vc = 12(1 e t /( RC ) ) . Likewise, the capacitor

dv

current is given by ic = C c = (12 / R)e t /( RC ) .

dt

To create a plot in Matlab we evaluate these two equations in an m-file for a range of

values of time and plot the result. Matlab provides for several plot options and there are

several ways to arrange the program itself. Since you are familiar with the C

programming language the most obvious solution would be to write a simple for loop to

evaluate the equations. Figure E2-2 shows an m-file which does this.

%Example2.m

R = 1000; %set the value of R and C as 1k and 1uf

C = 1e-6;

t = 0:.0001:.01; %t is a vector from 0 to .01 in steps of .0001

%Use a loop to evaluate the voltage and current equations

for i=1:length(t);

vc(i) = 12*(1-exp(-t(i)/(R*C)));

ic(i) = 12*exp(-t(i)/(R*C));

end

figure(1);clf; %Assign a figure number and clear figure

plot(t, vc); %plot time vs capacitor voltage

title('Capacitor voltage'); %Create a title for this graph

xlabel('Time'); %label the x axis

ylabel('Volts'); %label the y axis

figure(2);clf; %A second figure for the current

plot(t, ic); %plot time vs capacitor current on fig 2

title('Capacitor current'); %add titles and axis labels.

xlabel('Time');

ylabel('milliamps');

Figure E2-2

An m-file named Example2.m which uses a for loop to evaluate and plot the capacitor

voltage and current against time in two different figures.

Note that the line t = 0:.0001:.01; creates an array named t which has 101 values

ranging from 0 to .0001 in steps of .01. Also note that in Matlab no variables need to be

declared before they are used. Even arrays can be used without declaring them or

assigning them a dimension. On occasion it is necessary to declare an array and give it a

size and you can use the zeros functions to do this, but for the most part, Matlab is able to

figure out the variable type and array size from the context in which the variable is used.

for i=1:length(t);

vc(i) = 12*(1-exp(-t(i)/(R*C)));

ic(i) = 12*exp(-t(i)/(R*C));

end

is a standard for loop structure which creates two new arrays called vc and ic. It fills

these arrays with the values of the capacitor voltage and the capacitor current from the

equations which it evaluates.

Since t and vc are both arrays of the same size they can be plotted against one another

with the simple statement plot(t, vc); The program also adds titles and labels to the

plots. The result of the program is two new figures called figure(1) and figure(2) which

are shown below in Figure E2-3.

Capacitor voltage

12

10

8

Volts

0

0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01

Time

Capacitor current

12

10

8

milliamps

0

0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01

Time

Figure E2-3

The voltage (top) and the current (bottom) for the capacitor in this example. These two

figures were produced by Matlab running the m-file shown in Figure E2-2.

Solution using vectors

For those who are accustomed to other programming languages the looping structure

used in this example is a natural way to create the solution. But Matlab executes loops

rather slowly and it provides a much cleaner way of solving this problem. In Matlab it's

possible to write a single equation that operates on a vector or a matrix instead of having

to put the vector in a loop and operating on its elements piecemeal. Thus in Matlab we

can write

t = 0:.0001:.01; %t is a vector from 0 to .01 in steps of .0001

vc = 12*(1-exp(-t/(R*C)));

ic = 12*exp(-t/(R*C));

No loop is necessary. Since t is a vector, Matlab will make vc and ic vectors and evaluate

the equation for each element of t and store the results in vc and ic. Matlab is much more

efficient at evaluating vectors than it is at doing loops. It's not always possible to avoid a

loop and make use of vectors but you should do so when you can. Figure E2-4 shows the

m-file using the vector operations. It produces the same results as before.

%Example2.m

R = 1000; %set the value of R and C as 1k and 1uf

C = 1e-6;

t = 0:.0001:.01; %t is a vector from 0 to .01 in steps of .0001

%use vector operations to find vc and ic.

vc = 12*(1-exp(-t/(R*C)));

ic = 12*exp(-t/(R*C));

figure(1);clf; %Assign a figure number and clear the figure

plot(t, vc); %plot time vs capacitor voltage

title('Capacitor voltage'); %Create a title for this graph

xlabel('Time'); %label the x axis

ylabel('Volts'); %label the y axis

figure(2);clf; %A second figure for the current

plot(t, ic); %plot time vs capacitor current on figure 2

title('Capacitor current'); %add titles and axis labels.

xlabel('Time');

ylabel('milliamps');

Figure E2-4

An m-file which evaluates the equations for the capacitor voltage and current as vector

equations instead of loops.

Matlab provides subplots and other options that allow a user to put more than one plot on

a figure. The subplot function takes three arguments that specify the number of rows and

columns of subplots to be shown and the number of the currently selected subplot. For

example subplot(3,2,1) specifies that the current figure should have 3 rows by 2

columns of subplots and that we have currently selected the first subplot. The subplots

are numbered from left to right and top to bottom beginning with 1.

For this example we have just 2 plots so we can specify 2 rows and 1 column of subplots

for our figure. The new m-file to use subplots and the results are shown below.

%Example2.m

R = 1000; %set the value of R and C as 1k and 1uf

C = 1e-6;

t = 0:.0001:.01; %t is a vector from 0 to .01 in steps of .0001

vc = 12*(1-exp(-t/(R*C)));

ic = 12*exp(-t/(R*C));

figure(1);clf; %Assign a figure number and clear the figure

subplot(2, 1, 1); %specify subplots and choose the first

plot(t, vc); %plot time vs capacitor voltage

title('Capacitor voltage'); %Create a title for this graph

xlabel('Time'); %label the x axis

ylabel('Volts'); %label the y axis

subplot(2, 1, 2); %choose the second subplot in figure 1

plot(t, ic); %plot time vs capacitor current on

figure

title('Capacitor current'); %add titles and axis labels.

xlabel('Time');

ylabel('milliamps');

Figure E2-5

This version of the solution plots the results in subplots as shown in Figure E2-6.

Capacitor voltage

15

10

Volts

0

0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01

Time

Capacitor current

15

10

milliamps

0

0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01

Time

Figure E2-6

This is all one figure in Matlab but the figure has 2 rows and 1 column of subplots. The

top subplot shows the capacitor voltage vs time while the bottom subplot shows the

capacitor current vs. time.

- AC_Circuits_LAB.pdfUploaded byBien Basbas
- Ch07_StdUploaded byMohsan Bilal
- Transient1 Rl RcUploaded byKhalidBader
- Fundamentals of Switching PhenomenonUploaded byKopi143
- Charging & Discharging of CapacitorUploaded byraj
- TransientUploaded byNeas Ginting
- Class 6Uploaded byKunal Ramnatsing
- 2008physics1 Web CopyrgtUploaded byAce Asher
- 27102B473JO0(capacitor)Uploaded byMUHAMMAD SISWANTORO
- EC303Uploaded byapi-3853441
- transientUploaded bysumithra
- Phasor Method of Solving CircuitsUploaded byNayvi Kirkendall
- Wave Shaping CircuitsUploaded byParesh Sawant
- ObservationsUploaded byDavy Mardamootoo
- Transient ResponseUploaded bysbgm
- Part Test IUploaded byChetan
- BLR CX Short ManualUploaded bykachada22
- Edexcel Physics Experiment SheetsUploaded byMuhammad Shafnoon Kabir
- qp-nov_2010-4-1-eee-ehvact.pdfUploaded bykpchakrala
- ee-spx30csm2162.pdfUploaded byYung Lin
- List of experiments Unit 6.pdfUploaded byAkhlak Hossain
- Power Supply and Security Alarm ProjectUploaded byDhruv Gupta
- ADC Ads7818Uploaded byDark_Dolvar
- Trial P2 2018Uploaded bydanial
- Ongc Sample PaperUploaded byAnshul Agarwal
- Chapter 3rdUploaded bypunith gowda
- lec15Uploaded byCrow
- Practice Midterm 1.1 v2Uploaded bygolemisgreeaaaat
- GridSense Product OverviewUploaded byChenna Kesav
- iCP-440 Capacitor Bank Protection RelayUploaded byqwkerbk090909

- iitdpresentation2-130116121320-phpapp01Uploaded bySaurabh Shukla
- Lesson 1Uploaded bySaurabh Shukla
- OopUploaded bySaurabh Shukla
- Lesson 2Uploaded bySaurabh Shukla
- Interview Prep for Junior QuantsUploaded byjjusufz
- Interview Prep for Junior QuantsUploaded byjjusufz
- COMPUTER NETWORKS- LAB-2-Explaining HTTP Traffic Using WiresharkUploaded bynaveen jaiswal
- Information retrievalUploaded bysushi08
- Interview Prep for Junior QuantsUploaded byjjusufz
- c8169e61c8a9d6d2aefd99a67c1b017e_44ffb3feebe264ecb8efe5f98d473d19Uploaded bySaurabh Shukla
- ProgramUploaded bySaurabh Shukla
- Prml Slides 3Uploaded bySaurabh Shukla
- hass poset diagramsUploaded bySaurabh Shukla
- Class Normalization IIIUploaded bySaurabh Shukla

- Optix OSN 1500-Hardware DescriptionUploaded byLuis Angel Cortes Buitrago
- Euro Truck SimulatorUploaded bypiyush_sensational
- Protel 2004 Training ManualUploaded byCiptoz Ozaragi
- tencent.bat.txtUploaded byCJ Sinangote
- Demag ZKKE ManualUploaded byAlan Macias
- Https Nget.irctc.co.in Eticketing PrintTicket1Uploaded byAbdul Gani
- Sales Document Screen Sequence Control _ SAP BlogsUploaded byMirjana Radosavkic
- Raspberry Pi DropCam Alternative 05-03-2016 22.24.18 [Selectable PDF]Uploaded bySteve Attwood
- ResumeUploaded byAashiha Priyadarshni Lakshmi Kumar
- Itronix SolutionUploaded byadeol5012
- Dbms Output Put LineUploaded bySreenivasa R Peruri
- MSVMpackUploaded bymkiran02
- An Introduction to the Finite Element Method-COMSOLUploaded byJUAN4201
- 3 d ModellingUploaded bySofyan Darmawan
- Dr a Kangaiammal and Dr c Senthamarai Phd Scholar m Sandya March April 2013Uploaded byRamaswamy Periaswamy
- Supplier Conversion CV040Uploaded bysvsk_79
- IPR infringement in cyberspace: proposed guidelines for developing a modern policy frameworkUploaded byInternetSociety
- Java Aap LetUploaded byChaitAnya Märellä
- Customer Solution Case Study GetronicsUploaded byjafotech
- A Study on Capabilities and Functionalities of Security Information and Event Management Systems(SIEM)Uploaded byEditor IJRITCC
- [IJCST-V5I5P1]: D. Priyanka, Dr. K. Fathima BibiUploaded byEighthSenseGroup
- Steps to Recover SVCHOSTUploaded bycalifbob51
- 24535004 a Lesson in Outer JoinsUploaded bykalyan_ji
- Lean IT Enabling and Sustaining Your Lean TransformationUploaded byAhmed Hamdy Soliman
- Qf ServerUploaded bysschaffer345
- 8. IOT Base Smart Home Appliances by Using Cloud Intelligent Tetris SwitchUploaded bynadeemq_0786
- UntitledUploaded byapi-33597416
- AnaPalmero ResumeUploaded byAna Paula
- Projext v1Uploaded bypoof
- Static Search WorkingUploaded bySheikh Faizan Azmat