Question

In: Physics

Consider a simple electrical circuit where you charge a capacitor through a resistor by connecting a...

Consider a simple electrical circuit where you charge a capacitor through a resistor by connecting a battery (closing the switch) at time t=0.

The charge Q on the capacitor is related to the current I by dQ/dt=I. Furthermore, by Kirchhoff’s law, V – RI – Vc =0, and the charge Q on the capacitor is Q=CVc, where C is the capacitance. That can be combined to give the differential equation

dQ/dt = V/R - Q/RC

The analytic solution is Q(t)=CV(1 – exp(-t/(RC)). Write a MATLAB code that solves the differentia equation with the Euler forward method, Predictor-Corrector method, and Runge Kutta 4th Order. Use values of 1F for the capacitor, 10 Ohm for the resistor, and 10 V for the battery. Run the code from 0 to 10 seconds. Use values for dt of 1.0, 0.1, and 0.01. For each of the runs calculate the percentage error at the end, and make a table of the errors. Discuss and submit the table and only the first plot for Euler/dt=1. Which dt and how many step do you need with each of the methods to achieve an accuracy of better than 0.01%?

Solutions

Expert Solution

dt=[1 .1 .01];

C=1;

R=10;

V=10;

ode=@(t,Q)(V/R-Q/(R*C));

exact=C*V*(1-exp(-10/(R*C)));

for j=1:3

h=dt(j);

t=0:h:10;

yHeun=zeros(size(t));

yHeun(1)=0;

yEul=yHeun;

for i=2:length(t)

w=yHeun(i-1)+h*ode(t(i-1),yHeun(i-1));

yHeun(i)=yHeun(i-1)+(h/2)*(ode(t(i-1),yHeun(i-1))+ode(t(i),w));

end

for i=2:length(t)

yEul(i)=yEul(i-1)+h*ode(t(i-1),yEul(i-1));

end

figure

plot(t,yEul)

title(['Euler method, dt = ',num2str(h)])

figure

plot(t,yHeun)

title(['Predictor Corrector method, dt = ',num2str(h)])

percEr_Eul=abs((yEul(end)-exact)/exact)*100;

percEr_Heun=abs((yHeun(end)-exact)/exact)*100;

fprintf('Euler Method, dt = %.2f,percentage error: %f\n',h,percEr_Eul)

fprintf('Predicter Corrector Method, dt = %.2f,percentage error: %f\n',h,percEr_Heun)

end

Command window


Related Solutions

Suppose an electrical circuit contains a 1 H inductor, a 10 Ω resistor and a capacitor...
Suppose an electrical circuit contains a 1 H inductor, a 10 Ω resistor and a capacitor rated at 1/7 F. If the circuit is hooked up to an alternating voltage source described by E(t) = 68 cost V and initially q(0) = 1 C and i(0) = 0 A, find a function that describes the charge as a function of time.  Lq'' + Rq' + q/C = E(t).   Please show work using a complementary and particular solution if possible.
A 15μF capacitor has an initial charge of 50μC. It is discharged through an 8000Ω resistor....
A 15μF capacitor has an initial charge of 50μC. It is discharged through an 8000Ω resistor. Find: a) the current at 17ms; mA b) the charge at 17ms; μC c) the power loss in the resistor at 17ms. mW d) How long does it take for the energy in the capacitor to drop to 20% of its initial value? ms
When a Capacitor in an RC circuit is charging, current through the resistor:  increases/ decreases/ stays the...
When a Capacitor in an RC circuit is charging, current through the resistor:  increases/ decreases/ stays the same When a Capacitor in an RC circuit is discharging, current through the resistor:  increases/ decreases/ stays the same When a Capacitor in an RC circuit is charging, charge on the plates:  increases/decreases/stays the same When a Capacitor in an RC circuit is discharging, charge on the plates:  increases/decreases/stays the same When a Capacitor in an RC circuit is charging, voltage on the plates:  increases/decreases/stays the same When...
A capacitor is discharged through a 30 resistor.
A capacitor is discharged through a \(30{\Omega}\) resistor. The discharge current decreases to27 \({\%}\) of its initial value in \(1.7 \mathrm{~ms}\). What is the value of the capacitor in \(\mu F ?\) Express your answer using two significant figures.
What is the maximum charge on a capacitor in an RC circuit? As the capacitor in...
What is the maximum charge on a capacitor in an RC circuit? As the capacitor in an RC circuit charged, what is the current as a function of time?Explain your answer physically. 1.5 V batteries are usually connected in series. Would the batteries last longer or shorter if they were connected in parallel instead?
2.00-nF capacitor with an initial charge of 5.35 µC is discharged through a 1.23-kΩ resistor. (a)...
2.00-nF capacitor with an initial charge of 5.35 µC is discharged through a 1.23-kΩ resistor. (a) Calculate the current in the resistor 9.00 µs after the resistor is connected across the terminals of the capacitor. (Let the positive direction of the current be define such that dQ dt > 0.) How is the instantaneous current related to the potential difference across the capacitor? mA (b) What charge remains on the capacitor after 8.00 µs? µC (c) What is the (magnitude...
A circuit consisting of a resistor, capacitor and power supply is called an RC circuit. Physics...
A circuit consisting of a resistor, capacitor and power supply is called an RC circuit. Physics and Kirchoff’s laws imply that if Q is the charge on the capacitor, R is the resistance and E is the power supply, then R(dQ/dt) + (1/C)Q = E. Let R = 20, C = .1 and E = 100e −.1t. If there is no charge on the capacitor at time t=0, find the charge Q at any time after that. In an RL...
A circuit is constructed with an AC generator, a resistor, capacitor and inductor as shown. The...
A circuit is constructed with an AC generator, a resistor, capacitor and inductor as shown. The generator voltage varies in time as ε =Va - Vb = εmsinωt, where εm = 120 V and ω = 231 radians/second. The inductance L = 155 mH. The values for the capacitance C and the resistance R are unkown. What is known is that the current in the circuit leads the voltage across the generator by φ = 49 degrees and the average...
A circuit is consisted of an inductor L, a capacitor C, and a resistor R. It...
A circuit is consisted of an inductor L, a capacitor C, and a resistor R. It is driven by an AC voltage of the form ?0sin (??). At the steady state, find (a) the charge and current as a function of time (b) the maximum amplitude of the current and the corresponding resonance frequency (c) the average power at the current’s resonance frequency (c) the quality factor Q
An RLC circuit is made up of a resistor R = 12Ω , a capacitor C...
An RLC circuit is made up of a resistor R = 12Ω , a capacitor C = 0.1 F and an inductor L = 2 H. A voltage source is connected that supplies 110 V. If initially the capacitor is discharged and no current flows through the circuit, find an expression for the charge at all times t. differential equations
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT