diff options
| author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-12-08 09:21:32 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-12-08 09:21:32 -0700 |
| commit | b5ad184c1bcef78e7c2b052bcffc71f4c7381bcb (patch) | |
| tree | f060afc8dc7e896ad48731b58b5414b4c6ab627b /test/jacobi.t.c | |
| parent | b8c662456f2caf219de2a21f137f8fd61e34b0b2 (diff) | |
| download | math-4610-b5ad184c1bcef78e7c2b052bcffc71f4c7381bcb.tar.gz math-4610-b5ad184c1bcef78e7c2b052bcffc71f4c7381bcb.zip | |
hw8 checkpoint
Diffstat (limited to 'test/jacobi.t.c')
| -rw-r--r-- | test/jacobi.t.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/jacobi.t.c b/test/jacobi.t.c new file mode 100644 index 0000000..dc13d6e --- /dev/null +++ b/test/jacobi.t.c @@ -0,0 +1,33 @@ +#include "lizfcm.test.h" +#include <math.h> + +Matrix_double *generate_ddm(size_t n) { + Matrix_double *m = InitMatrixWithSize(double, n, n, rand_from(0.0, 1.0)); + + for (size_t y = 0; y < m->rows; y++) { + m->data[y]->data[y] += sum_v(m->data[y]); + } + + return m; +} + +UTEST(jacobi, jacobi_solve) { + Matrix_double *m = generate_ddm(2); + + Array_double *b_1 = InitArrayWithSize(double, m->rows, 1.0); + Array_double *b = m_dot_v(m, b_1); + + double tolerance = 0.001; + size_t max_iter = 400; + Array_double *solution = jacobi_solve(m, b, tolerance, max_iter); + + for (size_t y = 0; y < m->rows; y++) { + double dot = v_dot_v(m->data[y], solution); + EXPECT_NEAR(b->data[y], dot, 0.1); + } + + free_matrix(m); + free_vector(b_1); + free_vector(b); + free_vector(solution); +} |
