-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathLinear_Homogeneous_Recurrence_Relations_with_Constant_Coefficients.py
82 lines (63 loc) · 2.61 KB
/
Linear_Homogeneous_Recurrence_Relations_with_Constant_Coefficients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import sympy as sp
# Define the symbolic variable 'r' and the recurrence relation
r = sp.symbols('r')
recurrence_relation = r**2 - 3*r + 2
# Solve the characteristic equation for the roots (values of 'r')
roots = sp.solve(recurrence_relation, r)
print("Roots of the equation:", roots)
# Define the homogeneous solution of the difference equation
homogeneous_solution = [sp.Symbol(f'C{i}') * r**i for i in range(len(roots))]
print("Homogeneous Solution:")
for i, solution in enumerate(homogeneous_solution):
print(f"yK = {solution}")
# Define the symbolic variable 'K' and the recurrence relation
K = sp.symbols('K')
recurrence_relation = 9*K**2 - 6*K + 1
# Solve the characteristic equation for the roots (values of 'K')
roots = sp.solve(recurrence_relation, K)
print("Roots of the equation:", roots)
# Define the homogeneous solution of the difference equation
homogeneous_solution = [sp.Symbol(f'A{i}') * K**i for i in range(len(roots))]
print("Homogeneous Solution:")
for i, solution in enumerate(homogeneous_solution):
print(f"yK = {solution}")
# Define the symbolic variable 'K' and the recurrence relation
K = sp.symbols('K')
recurrence_relation = K**2 - K - 1
# Solve the characteristic equation for the roots (values of 'K')
roots = sp.solve(recurrence_relation, K)
print("Roots of the equation:", roots)
# Define the homogeneous solution of the difference equation
homogeneous_solution = [sp.Symbol(f'X{i}') * K**i for i in range(len(roots))]
print("Homogeneous Solution:")
for i, solution in enumerate(homogeneous_solution):
print(f"yK = {solution}")
# Define the symbolic variable 'K' and the recurrence relation
K = sp.symbols('K')
recurrence_relation = K**4 + 4*K**3 + 8*K**2 + 8*K + 4
# Solve the characteristic equation for the roots (values of 'K')
roots = sp.solve(recurrence_relation, K)
print("Roots of the equation:", roots)
# Define the homogeneous solution of the difference equation
homogeneous_solution = [sp.Symbol(f'Z{i}') * K**i for i in range(len(roots))]
print("Homogeneous Solution:")
for i, solution in enumerate(homogeneous_solution):
print(f"yK = {solution}")
# Answer: Roots of the equation: [1, 2]
# Homogeneous Solution:
# yK = C0
# yK = C1*r
# Roots of the equation: [1/3]
# Homogeneous Solution:
# yK = A0
# Roots of the equation: [1/2 - sqrt(5)/2, 1/2 + sqrt(5)/2]
# Homogeneous Solution:
# yK = X0
# yK = K*X1
# Roots of the equation: [-1 - I, -1 + I]
# Homogeneous Solution:
# yK = Z0
# yK = K*Z1