










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to MATLAB programming, focusing on the application of Runge-Kutta 2nd and 4th order methods for solving ordinary differential equations. Students will learn the basics of MATLAB, including commands, variables, and functions, before diving into the specifics of Runge-Kutta methods. The document also includes examples and explanations of the RK2 and RK4 methods, making it useful for students in engineering, physics, or mathematics fields.
Typology: Study notes
1 / 18
This page cannot be seen from the preview
Don't miss anything!











➢ Symbolic variable : To create symbolic expressions, first create symbolic variables, and then use operations on them. The syms command is a convenient shorthand for the ‘sym’ syntax. Declare variables x, y, m as symbolic i.e. syms x, y, m. For example:
syms x y E = x^2+6x+7; F = subs(E,x,y) F = y^2+6y+ ➢ MATLAB Pre-defined Constants (built-in) ➢ Statement or Row vector ‘ too long to fit in one line’:
➢ Commands for conversion from Polar to Cartesian coordinates and vice - versa ➢ Logical operators: AND, OR, NOT ➢ Trigonometric functions : ➢ Differenttiation and integration commands
➢ Polynomial function Commands ➢ Some Built-in Functions :
9.0 M-Files:
R=input('Enter R: '); C=input('Enter C: '); L=input('Enter L: '); w=input('Enter w: '); y=impedance(R, C, L, w); fprintf ('\n The magnitude of the impedance at %.1f rad/s is %.3f ohm\n', w, y(3)); fprintf ('\n The angle of the impedance at %.1f rad/s is %.3f degrees\n\n', w, y(4)); Coding: % function without brakets- whether the give no. lies between 10 & 100 or not function inrange a=input(‘enter the number=\n’); If ((a>10) & (a<100)) disp(‘The number lies betn 10 & 100’); else disp(‘The number does not lie betn 10 & 100’); end; 9 .1 Anonymous function : Creating simple functions without having to create m-files each time. Anonymous function can be constructed either at the MATLAB command line or in any m-file function or script.
The sign @is the MATLAB operator that constructs a function handle giving a means of invoking the function. Stores the value of the handle in variable fhandle Coding: a=1.3; b=0.2; c=30; parabola=@(x) ax.^2+bx+c; fplot (parabola, [-25 25])**
10. Plot Commands: ( follow any MATLAB reference Book) 11.0 Solving Differential Equations: Syntax: dsolve('eq1','eq2',...,'cond1','cond2',...,'v') eq1, eq2,... are the differential equations wrt the independent variable ,v. Letter ‘D’ denotes differentiation of the function ‘y’ with respect to the independent variable (t). Dy is dy/dt, D2y is d^2 y /dt^2 , D3y is d^3 y /dt^3. ...Dny is dny /dtn^ , indicating first ,second, third and nth derivative of the function (y) wrt the independent variable,t**.
dsolve(’D2y=c^2y’,’y(0)=1’,’Dy(0)=0’)* ans = 1/2exp(ct)+1/2exp(-ct) >>dsolve(’Dx=3x+4y’,’Dy=-4x+3y’, ’x(0)=0’,’y(0)=1’)** [x,y] = x = exp(3t)sin(4t), y = exp(3t)cos(4t) Solving Ordinary Differnential Equation (ODE):
7.0 RK2 and RK4 Methods: The diff equations to be solved in power system stability analysis are nonlinear ordinary differential equations with known initial values: d y /dx = f(x,y) where y is the state vector of n dependent variables and x is the independent variable. Our objective is to solve y as a function of x, with initial values of y and x equal to y 0 and x 0 respectively. There are many algorithms to solve such engineering problems, and Runge-Kutta method is one of them.
Taylor Series: Euler’s Method: ➢ A numerical technique to solve ordinary differential equations of the form
Backward Euler’s Method: We start at the initial point (x 0 , y 0 ). Here, the derivative is to be evaluated at point (x + h) instead of at point h. To obtain the next point, (x 1 , y 1 ), we take the derivative at x 1 (not at x 0 !) and extrapolate it at point (x 0 , y 0 ). Hence Backward Euler’s method gives us, y 1 = y 0 + hf(x 1 , y 1 ). Similarly, at (x 1 , y 1 ) we have y 2 = y1 + hf(x 2 , y 2 ). In general, y n+1 = yn + h f(x n+1, yn+1),
Where,
[If f is independent of t, the differential equation is equivalent to a simple integral, then RK4 is Simpson's rule, and If f is independent of t (so called autonomous system, or time-invariant system, especially in physics), and their increments are not computed at all and not passed to function f] 7.3 Example of Runge-Kutta Method Solve
y (0) = 0_._ 5 for 0 ≤ t ≤ 2 and h=0. Exact solution for the problem is y = t^2 + 2 t + 1 – ½(et^ )
Step size h = 0****. 5. For t = 0 to t = 1, steps: t 0 = 0, t 1 = 0****. 5, t 2 = 1, t 3 = 1****. 5, t 4 = 2. Step 0: t0 = 0, y0 = 0.