Numerical Solution RL Circuit
Post on 26-Dec-2015
Embed Size (px)
DESCRIPTIONSimulation of RL Circuit using Numerical methods
Trapezoidal MethodThe trapezoid method averages theEulerandbackward Eulermethods, 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 valueykat timetkfor an ODEy =f(x,y), the trapezoid method approximates the solutiony(xk+1)at time xk+1=xk+hkby solving the implicit equationyk+1=yk+hk[f(xk,yk) +f(xk+1,yk+1)] 2foryk+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:
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 :
StartAlgorithm for Trapezoidal Method
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
Newton function: Iterate the above equation till required convergence is achived.
Store the yn+1 corrected value to the Y axis array.
If xn+1=final value of x
Plot x and yExit Yes
Implementation of Algorithm Using MATLAB
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