MIDTERM_2_1

MIDTERM_2_1 - %Q(i 1)= Q(i(h(R*C*Q(i(V*h/R%This line shows...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% Charging a capacitor using Euler's Loop Method to solve the DIFFY-Q % The charge and current as a function of time on a capacitor in an RC % circuit % Charging a capacitor h = 1; % time increments R = 1e6; % the resistance in ohms C= 1e-5; % the capacitance in farads V=10 ; % the voltage of the power supply a = 0; % the starting time b = 60; % the ending time >= 6RC m = (b - a) / h; Q = zeros(1, m+1); Q(1) = 0; t = a:h:b; for i = 1:m Q(i+1)=Q(i)+exp(-t./(R*C)).*(V*h)/R;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %Q(i+1)= Q(i)-(h/(R*C))*Q(i)+(V*h)/R; %This line shows diff eqn end Qex = C*V*(1- exp(-t/(R*C))); %This is the exact solution from analytical %integration I=[(1/h)*diff(Q),0] format bank disp( [t' Q' Qex'] ) subplot(1,2,1) plot(t, Q,'r') xlabel( 'time in seconds' ), ylabel( 'charge on capacitor in coulombs' ) hold on plot(t, Qex ), hold off subplot(1,2,2) plot(t,I,'k') xlabel( 'time in seconds' ), ylabel( 'current in the circuit in amps' )...
View Full Document

This note was uploaded on 09/15/2011 for the course EE 150 at USC.

Ask a homework question - tutors are online