{"id":21766372,"url":"https://github.com/drilonaliu/numerical-analysis-2","last_synced_at":"2025-03-21T05:24:14.317Z","repository":{"id":59769201,"uuid":"539097254","full_name":"drilonaliu/Numerical-Analysis-2","owner":"drilonaliu","description":"A package for numerical analysis with matrices, norms, finding eigenvalues and eigenvectors, and iterative methods for solving system of linear equations. ","archived":false,"fork":false,"pushed_at":"2022-09-22T19:03:30.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T02:18:23.931Z","etag":null,"topics":["linear-algebra","matrix","norm","numerical-analysis","numerical-analysis-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drilonaliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-20T16:52:35.000Z","updated_at":"2022-11-10T17:03:03.000Z","dependencies_parsed_at":"2023-01-18T17:25:42.979Z","dependency_job_id":null,"html_url":"https://github.com/drilonaliu/Numerical-Analysis-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FNumerical-Analysis-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FNumerical-Analysis-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FNumerical-Analysis-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FNumerical-Analysis-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drilonaliu","download_url":"https://codeload.github.com/drilonaliu/Numerical-Analysis-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244741951,"owners_count":20502381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linear-algebra","matrix","norm","numerical-analysis","numerical-analysis-algorithms"],"created_at":"2024-11-26T13:17:02.537Z","updated_at":"2025-03-21T05:24:14.290Z","avatar_url":"https://github.com/drilonaliu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numerical-Analysis-2\n\nA package for Numerical Analysis 2 course I wrote for my class, including:\n\n  1. Matrix and vector operations( addition, multiplication..)\n  2. Models for complex numbers, complex matrix and complex vectors.\n  2. Infinity norm, euclidian norm(for vectors), Frobenious norm(matrices).\n  3. Matrix convergence test.\n  4. Power method for finding eiugenvalues and eiguenvector of a Matrix.\n  5. Expansion of a matrix A with complex numbers to a matrix twice as big with a matrix with real numbers. \n  6. Jacobi Iterative and Gauss Seidel  methods for solving system of linear equations. \n\n\n ### Matrix convergence test \n A $nxn$ matrix $A$ is called convergent if \n \n$\\displaystyle \\lim_{k \\to \\infty} (A^k)_{ij} = 0$ for each  $i = 1, 2, . . . , n$ and $j = 1, 2, . . . n$. The algorithm would follow \n\n    Input: Matrix A, n0 (max number of iterations), TOL\n    Output: true or false \n    S1: set A1 = A\n    S2: set k = 1\n    S3: while k\u003c=n0 do S4 - S6\n    S4: set A = A*A1\n    S5: if $|a_i|$ \u003c TOL, for each  $i = 1, 2, . . . , n$ and $j = 1, 2, . . . n$, then  \n        Output(The matrix A converges)\n        STOP\n    S6  k := k+1;\n    S7 Output(Tolerance was not met within the max number of iterations).\n\nAnd in java the implentation went \n  \n      public boolean converges(double tol, int max) {\n        Matrix M1 = new Matrix(M);\n        double[][] A;\n        boolean found = false;\n        int k = 1;\n        while (k \u003c= max \u0026\u0026 !found) {\n            M1 = M1.multiply(this);\n            A = M1.getPrimitive();\n            boolean converge = true;\n            for (int i = 0; i \u003c rows \u0026\u0026 converge; i++) {\n                for (int j = 0; j \u003c columns; j++) {\n                    if (Math.abs(A[i][j]) \u003e tol) {\n                        converge = false;\n                        break;\n                    }\n                }\n            }\n            if (converge) {\n                found = true;\n            }\n            k = k + 1;\n        }\n        return found;\n    }\n\n## Expansion of a complex matrix A to a real matrix twice as big.\n\nThe number $\\lambda$ is called an eiguenvalue of matrix A if  \n\n$$Ax =\\lambda\\ x$$ \n\n$$ =\u003e(A- \\lambda I)x = 0 $$\n\nThis homogeneous system of equations has nonzero solutions if and only if the coefficient matrix $(A- \\lambda I)$ is singular; that is, if and only if\nthe determinant of $(A- \\lambda I)$ is zero.\n\nWhen $\\lambda$ is a complex number, we should expand the complex matrix to a real one, which is best demonstrated by the following example. Let us find the eiguen value of the matrix A.\n\n$$ \nA =\n\\begin{pmatrix}\n1 \u0026 0 \u0026 -2 \\\\\n0 \u0026 1 \u0026 -1 \\\\\n-1 \u0026 1 \u00261 \\\\\n\\end{pmatrix}\n$$\n\n$$det(A-\\lambda I)=\\lambda (1-\\lambda)(\\lambda^2-2\\lambda+4)$$ \n\n\n$$det(A - \\lambda I) = 0 =\u003e \\lambda_1 = 1, \\lambda_2=1+i\\sqrt3, \\lambda_3=1-i\\sqrt3$$\n\nFinding euiguen vector when $\\lambda = 1+i\\sqrt3$, we have \n\n$$(A- (1+i\\sqrt3) I)x = 0 =\u003e\n\\begin{pmatrix}\n-i\\sqrt3 \u0026 0 \u0026 2 \\\\\n0 \u0026 -i\\sqrt3 \u0026 -1\\\\\n-1 \u0026 1 \u0026-i\\sqrt3 \\\\\n\\end{pmatrix}\n\\begin{pmatrix}\nx_1 \\\\\nx_2 \\\\\nx_3 \\\\\n\\end{pmatrix} = \n\\begin{pmatrix}\n0 \\\\\n0 \\\\\n0 \\\\\n\\end{pmatrix}\n$$\n\nSetting $x_i=a_i+ib_i$. Solving system \n\n$$\\begin{pmatrix}\n-i\\sqrt(3) \u0026 0 \u0026 2 \\\\\n0 \u0026 -i\\sqrt3 \u0026 -1\\\\\n-1 \u0026 1 \u0026-i\\sqrt3 \\\\\n\\end{pmatrix}\n\\begin{pmatrix}\na_1+ib_1 \\\\\na_2+ib_2 \\\\\na_3+ib_3 \\\\\n\\end{pmatrix} = \n\\begin{pmatrix}\n0 \\\\\n0 \\\\\n0 \\\\\n\\end{pmatrix}\n$$\n\n$$\n=\u003e\n\\begin{pmatrix}\n0a_1 -ia\\sqrt3 a_3 + \\sqrt3 b_1 + 0b_1 + 0a_2 +0ia_2 + 0b_2 +0ib_2 + 2a_3+0ia_3+0b_3+2ib_3 \\\\\n0a_1 + 0ia_1 + 0b_1 + 0ib_1 + 0a_2-i\\sqrt3 a_2+\\sqrt3b_2+0i(b_2) -a_3+0ia_3 +0b_3-ib_3 \\\\\n-1a_1+0ia_1+0b_1-ib_1 +a_2+0ia_2 +0b_2+ib_2+0a_3-i\\sqrt3 a_3 + \\sqrt3 b_3+0ib_3 \\\\\n\\end{pmatrix} = \n\\begin{pmatrix}\n0 \\\\\n0 \\\\\n0 \\\\\n\\end{pmatrix}\n$$\n\nWhich is equivalent to solving \n\n$$\\begin{pmatrix}\n0 \u0026 \\sqrt3 \u0026 0 \u0026 0 \u0026 2 \u0026 0 \\\\\n-\\sqrt3 \u0026 0 \u0026 0\u0026 0 \u0026 0 \u0026 2 \\\\\n0 \u0026 0 \u0026 0 \u0026 \\sqrt3 \u0026 -1 \u0026 0 \\\\\n0 \u0026 0 \u0026 -\\sqrt3 \u0026 0 \u0026 0 \u0026 -1 \\\\\n-1 \u0026 0 \u0026 1 \u0026 0 \u0026 0 \u0026 \\sqrt3 \\\\\n0 \u0026 -1 \u0026 0 \u0026 1 \u0026 -\\sqrt3 \u0026 0 \\\\\n\\end{pmatrix}\n\\begin{pmatrix}\na_1\\\\\nb_1\\\\\na_2\\\\\nb_2 \\\\\na_3 \\\\\nb_3 \\\\\n\\end{pmatrix} = \n\\begin{pmatrix}\n0\\\\\n0\\\\\n0\\\\\n0 \\\\\n0 \\\\\n0 \\\\\n\\end{pmatrix}\n$$\n\n\nThe 6x6 matrix was obtained by getting the constats of each row  near $a_k,b_k$ and $ia_k, ib_k$, $\\forall k \\in {1,2,3}$ . So each row of a 3x3 matrix is divided into two rows, the first row with only real constants near $a_k,b_k$, and the second row with constants near $ia_k,ib_k$.\n\n![matrixca 3](https://user-images.githubusercontent.com/84543584/191829991-9627917b-5ff6-4f71-9c39-f25acb6e59ac.png)\n\n\n### Making the expanding algorithm\n\nLet $z_{ij}=c_{ij} + id_{ij} \\in A, \\forall i,j \\in {{1,2,3}}$\nNote that \n\n $z_{ij}(a_j+ib_j) = (c_{ij}+id_{ij})(a_j+ib_j) = {\\color{red}c_{ij}}a_j + i{\\color{blue}d_{ij}}a_j -{\\color{red}d_{ij}}b_j+i{\\color{blue}c_{ij}}b_j$\n \n So for the i-th row of 3x3 matrix in (1), we know now the coefficients near $a_j,b_j,ia_j,ib_j$, which are $c_{ij},-d_{ij},d_{ij},c_{ij}$, which is $Re(z),-Im(z),Im(z),Re(z)$ respectfully.\n Now based on this rule, we iterate through each element of the matrix A in (1) and fill it the 6x6 matrix with constants near $a_k,b_k$ and $ia_k, ib_k$.\n  \n    public Matrix expandToReal() {\n          int n = rows;\n          double[][] M = new double[2 * n][2 * n];\n          for (int i = 0; i \u003c CM.length; i++) {\n              for (int j = 0; j \u003c CM.length; j++) {\n                  Complex Z = this.get(i, j);\n                  double c_ij = Z.getReal();\n                  double d_ij = Z.getImaginary();\n                  M[2 * i][2 * j] = c_ij;\n                  M[2 * i + 1][2 * j] = d_ij;\n                  M[2 * i][2 * j + 1] = -1.0 * d_ij;\n                  M[2 * i + 1][2 * j + 1] = c_ij;\n              }\n          }\n          return new Matrix(M);\n      }\n   \nAnd voila, testing the algorithm we get the same 6x6 expanded matrix we got above\n \n ![image](https://user-images.githubusercontent.com/84543584/191826023-cb1b1e1b-4873-4997-898e-b305d0e3cf76.png)\n\nYes, I was lazy to try and print the matrix better.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fnumerical-analysis-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrilonaliu%2Fnumerical-analysis-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fnumerical-analysis-2/lists"}