The square root method solves systems of linear equations
import numpy as np
def pingfagenfa(a):
n = a.shape[0]
g = np.mat(np.zeros((n, n), dtype=float))
g[0, 0] = np.sqrt(a[0, 0])
g[1:, 0] = a[1:, 0]/g[0, 0]
for j in range(1, n-1):
g[j, j] = np.sqrt((a[j, j] - np.sum(np.multiply(g[j, 0:j], g[j, 0:j]))))
for i in range(j+1, n):
g[i, j] = (a[i, j] - np.sum(np.multiply(g[i, 0:j], g[j, 0:j])))/g[j, j]
g[n-1, n-1] = np.sqrt((a[n-1, n-1] - np.sum(np.multiply(g[n-1, 0:n-1], g[n-1, 0:n-1]))))
return g
if __name__ == "__main__":
a = np.mat([[9, 18, 9, -27],
[18, 45, 0, -45],
[9, 0, 126, 9],
[-27, -45, 9, 135]], dtype=float)
print('G:')
G = pingfagenfa(a)
print(G)
The solution results are shown in the figure below:
column
Python is the direct method of solving linear equations (1) — – gaussian elimination
Python the direct method of solving linear equations (2) — – gaussian column main element elimination
Python the direct method of solving linear equations (3) — – column if primary element gauss – when elimination
Python the direct method of solving linear equations (4) — – LU decomposition of the matrix
Python the direct method of solving linear equations (5) — –
square root method to solve linear equations Python direct method for solving systems of linear equations (6) — chase method for solving tridiagonal equations
Python direct method for solving systems of linear equations (7) — givens transformation based QR decomposition
Python direct method for solving systems of linear equations (8) — haushalde transformation based QR decomposition
Read More:
- Solving equations and equations with MATLAB
- How to Solve differential equations with MATLAB
- Error: can’t access JTAG chain problem solving method
- The method of constructing even order magic square (n = 4 * m)
- Error analysis of multiple linear regression in R language model.frame.default
- Python judge perfect square number
- Square root of X (implementation of binary search)
- Solving Python error: local variable ‘a’ referenced before assignment
- pyvista error: root:GLEW could Missing GL version settlement method
- Detailed explanation of Python__ new__() method
- [leetcode] 926. Flip string to monotone increasing problem solving report (Python)
- Difference between isempty method and isblank method in stringutils
- “Method does not override method from its superclass”
- Python switch / case statement implementation method
- Linux update Python method and error handling
- The method of getting shell command output in Python
- Python 3.7 pyGame download method
- Solve the problem that power view in Excel prompts activate method of oleobject class failed or activate method like oleobject is invalid
- Error handling method of “no module named ‘stringio’” in Python 3
- Solve CONDA’s “solving environment: failed” problem