VOOZH about

URL: https://www.geeksforgeeks.org/matlab/solving-2nd-order-homogeneous-difference-equations-in-matlab/

⇱ Solving 2nd Order Homogeneous Difference Equations in MATLAB - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Solving 2nd Order Homogeneous Difference Equations in MATLAB

Last Updated : 5 Apr, 2022

Difference Equations are Mathematical Equations involving the differences between usually successive values of a function ('y') of a discrete variable. Here, a discrete variable means that it is defined only for values that differ by some finite amount, generally a constant (Usually '1'). A difference equation can also be defined as a relation between the difference of an unknown function at one or more general values how's the argument. For example equation Δyn+1+yn = 2, It can also be rewritten as: yn+2-yn+1+yn = 2 (Since, Δyn = yn+1-yn)

Order of a Difference Equation:

The Order of a Difference Equation can be found by the Relation: 

Example: Consider the Equation 3yn+2-yn+1+5yn = -12, The Order of it is:

Hence, The Order of the above Equation is '2'. So, It can be called a 2nd Order Difference Equation specific.

Homogeneous: If the R.H.S of the above equation is zero, then it can be called a 2nd Order Homogeneous Difference Equation in specific. 

Steps to Solve a 2nd Order  Homogeneous Difference Equation:

Step 1: Let the given 2nd Order Difference Equation is:

ayn+2+byn+1+cyn = 0

Step 2:Then, we reduce the above 2nd Order Difference Equation to its Auxiliary Equation(AE) form:

ar2+br+c = 0

Step 3:Then, we find the Determinant of the above Auxiliary Equation(AE) by the Relation:

Det = (b2 − 4ac)

Step 4:If the Determinant found above is Positive (2 Distinct Real roots r1 & r2), then the yn will be:

yn = C1r1n + C2r2n

Step 5:Else if the Determinant found above is Zero (2 Equal Real Root,r1=r2=r), then the yn will be:

yn = (C1n + C2)r1n

Step 6: Else if the Determinant found above is Negative (Complex Roots, r = α ± iβ), then the yn will be: 

yn = Pn(C1cos(nθ) + C2sin(nθ)),
where P = √(α22) and θ = tan-1(β/α)

If any Initial Conditions are given, like y0 = m and y1 = n, Then we substitute these two Equations in the above Equation and then we find the C1 & C2 by solving the equation we formed earlier by substitution. Then we resubstitute the C1 & C2 found in the equation 'yn'.

MATLAB Functions used in the Below Code are:

  • disp('txt'): This Method displays the message 'txt' to the User.
  • input('txt'): This Method displays the 'txt' and waits for the user to input a value and press the Return key.
  • solve(eq): This Method solves the 'eq' for the variable present in it.
  • abs(z): This method returns the complex modulus of z.
  • angle(z): This method returns the phase angle in the interval [-π,π] of z.
  • subs(y, old, new): This method returns a copy of y, replacing all occurrences of old with new.
  • simplify(eq): This Method performs algebraic simplification of 'eq'.

Example 1:

Output:

👁 Image
 
👁 Image
 

Example 2:

Output:

👁 Image
 
👁 Image
 
Comment