Numerical Solution RL Circuit

13
Trapezoidal Method The trapezoid method averages the Euler and backward Euler methods, advancing the approximate solution at each step along a line whose slope is the arithmetic mean of the derivatives at its endpoints. Specifically, from an approximate solution value y k at time t k for an ODE y′ = f(x, y), the trapezoid method approximates the solution y(x k+1 ) at time x k+1 = x k + h k by solving the implicit equation y k+1 = y k + h k [f(x k , y k ) + f(x k+1 , y k+1 )] ⁄ 2 for y k+1 . Since this equation may be nonlinear, solving it generally requires an iterative solution method. Any iterative method for solving this equation can be implemented such as bisection method,newton method. A graphical visualization of trapezoidal integration:

description

Simulation of RL Circuit using Numerical methods

Transcript of Numerical Solution RL Circuit

Page 1: Numerical Solution RL Circuit

Trapezoidal Method

The trapezoid method averages the Euler and backward Euler methods, advancing the approximate solution at each step along a line whose slope is the arithmetic mean of the derivatives at its endpoints. Specifically, from an approximate solution value yk at time tk for an ODE y′ = f(x, y), the trapezoid method approximates the solution y(xk+1) at time xk+1 = xk + hk by solving the implicit equation yk+1 = yk + hk [f(xk, yk) + f(xk+1, yk+1)] ⁄ 2 for yk+1. Since this equation may be nonlinear, solving it generally requires an iterative solution method. Any iterative method for solving this equation can be implemented such as bisection method,newton method.

A graphical visualization of trapezoidal integration:

The inegration by finding the area under it. So area under the f(x,y) is divided into large number of sub section. Area of one section [xo,x1] can be approximated as area of the dark shaded trapezoidal i.e:

Page 2: Numerical Solution RL Circuit

Area=Area of the trapezoid=

Differential equation Problem:

As we know that the solution of over [xn , xn+1] is

Applying simple trapezoidal rule we have :

Equation-1

It can also be represented as

Now the Equation-1 may be a nonlinear equation with root yn+1 . So any root finding methods can be used to solve this equation. Newton method can be used for finding the root of this equation. The solution of any equation by Newton method needs a good initial guess for convergence. The initial guess can be yn+1 from Euler method as

Initial guess :

With this initial guess Newton method iteration is started.

Newton Method :

And .

Page 3: Numerical Solution RL Circuit

Algorithm for Trapezoidal Method

No

Yes

Start

Inputs: Step Size(h), Initial Values of X and Y, Final Value of X

for solution, and

Create a array containing x axis required values. And a null initialization of Y axis values.

Create a initial guess for yn+1 from Euler method.

Create a function

Call Newton function

Store the yn+1 corrected value to the Y axis array.

If xn+1=final value of x

Newton function:

Iterate the above equation till required convergence is achived.

Plot x and y

Exit

Page 4: Numerical Solution RL Circuit

Implementation of Algorithm Using MATLAB

Main Program:

f=input('Enter the Function= ','s');h=input('Enter the step size: ');srt=input('From which value of x you want to start the solution: ' );last=input('Input upto how much you want to end the solution: ');x=srt:h:last;y=zeros(1,length(x)); % Output Matrixy(1)=input('Enter the initial condition for y at initial x: ');f=inline(f);i=2;while (i<=(length(x))) y(i)=eulers(x(i),h,y(i-1),char(f)); %y(i)=y(i-1) + h*f(x(i-1),y(i-1)); % Initial Guess for solving the Non linera Equation %f(n)=f(x(n),y(n)) % Trapezoidal Method: y(n)= y(n-1) + stepsize*0.5*(f(n-1)+f(n)) % which is a non linear Equation To be solved by Newton method % Taking 1st Guess as from Euler Method %Formulation Of string to call newton method: g(y)=0; i.e : g(y)=y(n)- y(n-1) - stepsize*0.5*(f(n-1)+f(n)) % For formulation of g(y), a symbolic variable p is defined..so % g(p)=0 can be sloved using Newton syms p; % A symbolic variable k=sym(h*0.5*f(x(i-1),y(i-1))); k=k+h*0.5*f(x(i),p); k=p-sym(y(i-1))-k; % k=g(p) The symbolic function y(i)=newton(char(k),y(i)); % Solution of nonlinear equation i=i+1; endplot(x,y);grid on;xlabel('x');ylabel('y');title('Solution ' );

Page 5: Numerical Solution RL Circuit

Euler Initial Guess Program:

This function is called to calculate the initial guess by dividing the [xn,xn+1] again in steps and the return initial guess.

. function [initial]=eulers(startx,step,starty,f) f=inline(f);for x=startx:0.01:(startx+step) starty=starty+0.01*f(startx,starty);endinitial=starty;

Newton’s Method Program:

function [y]=newton(f,starty)f=inline(f); % Input String to inline functiondf=sym(f); % symbolic function from inlline functiondf=diff(df); % Differntial of input function fdf=inline(char(df)); i=true(1); % logical varible with true value 1k=1;while(i) y=starty - f(starty)/df(starty); % Iteration of newton method er=y-starty; starty=y; k=k+1; if er<0.001 i=false(1); end endy=starty;

Page 6: Numerical Solution RL Circuit

Simulation of Electrical Circuits:

Electrical circuit can be simulated for transient analysis using differential equation solution methods numerically having first order characteristic equation. A given network of passive element and sources which is initially in a known state with respect to all voltages and currents. At a reference time t=0 the system is altered in a manner that can be represented by closing and opening of switch. The objective of simulation is to find current, voltage etc. with respect to time measured from the time when switch position is changed.

Simulation of RL Series Circuit

After switch is closed and taking the reference time t=0 the circuit will look like the given figure

The Krichhoff voltage equation for the ciruit is

This is a non homogenous linear first order equation and it can be rearranged as

Now we have a differential equation in the form of dy/dx=f(x,y).

R=1Ω, L=1mH,V=1V and Solving:

Note : Tc=1ms. So step size should be less than step size. And final value of t should be atleast 4Tc to analyze the circuit properly.

Page 7: Numerical Solution RL Circuit

Simulation of the circuit can be done with different initial current. Taking initial condition as 0A,-2A,3A the plot between current and time is

Fig-1. I0=0A Fig 2.I0=-2A

Fig-3 I0=3A

It can be observed that after some time the current is settled to V/R value. With any initial condition stead state value of current will be same as long as the values of components remain same.

Page 8: Numerical Solution RL Circuit

Simulation Parallel RC Circuit

After switch is closed at t=0 the circuit diagram of parallel RC circuit is

Krichhoff ‘s current equation to the upper node will give the equation as

It can be rearranged as .

Taking R=1Ω,I=1A, C=10mF, RC=Tc=10ms. The differential equation is

This can be solved to obtain the plot between values of voltages and current. Simulation can also

be done using different initial values of capacitor voltages.

Page 9: Numerical Solution RL Circuit

Fig-4 Vc0=0V Fig-5 Vc0=5V

Fig-6 Vc0= -3V

After some time voltage value always goes to steady state i.e IR irrespective of initial capacitor voltage.

Page 10: Numerical Solution RL Circuit

Transient Voltage Across The Switch

Below circuit is in the steady state and with the current of V/R. Now switch is suddenly opened at t=0 instant. Voltage across switch is calculated. All switches are non ideal in nature. Semiconductor switches have certain turn off time. After turnoff time switch will stop conducting. During turn off there will be very high voltage appearing across the switch due to decay in current as inductor will oppose the change in this current. Example :

R=20Ω,V=100V,L=2mHToff=10µs

Page 11: Numerical Solution RL Circuit

Voltage across the switch is 1100V during turn off time. The switch should be designed to withstand such voltages otherwise it will be damaged during operation.

Bibilography

1. ‘An Introduction To Numerical Analysis’ 2nd Ed. by Kendall E. Atkinson.2. ‘Network Analysis’ 3rd Ed by M.E Valkenburg3. MATLAB Documentation, www.mathwork.in