summaryrefslogtreecommitdiff
path: root/test/main.c
blob: 3551af221e45f28af3fbba23bac2ff113a6479a2 (plain)
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
#include "lizfcm.h"
#include <stdio.h>
#include <stdlib.h>

double f(double x) { return (x - 1) / (x + 1); }

int main() {
  //  printf("smaceps(): %.10e\n", smaceps());
  //  printf("dmaceps(): %.10e\n", dmaceps());
  //
  //  Array_double *v = InitArray(double, {3, 1, -4, 1, 5, -9, 3});
  //  Array_double *w = InitArray(double, {-2, 7, 1, -8, -2, 8, 5});
  //
  //  char v_s[256];
  //  char w_s[256];
  //  format_vector_into(v, v_s);
  //  format_vector_into(w, w_s);
  //
  //  printf("v: %s\n", v_s);
  //  printf("w: %s\n", w_s);
  //  printf("l1_norm(v): %f\n", l1_norm(v));
  //  printf("l2_norm(v): %f\n", l2_norm(v));
  //  printf("linf_norm(v): %f\n", linf_norm(v));
  //
  //  printf("l1_dist(v, w): %f\n", l1_distance(v, w));
  //  printf("l2_dist(v, w): %f\n", l2_distance(v, w));
  //  printf("linf_dist(v, w): %f\n", linf_distance(v, w));
  //
  //  double h = 0.001;
  //  printf("approx f'(1) w/ c.d.: %f\n", central_derivative_at(&f, 1, h));
  //  printf("approx f'(1) w/ fw.d.: %f\n", forward_derivative_at(&f, 1, h));
  //  printf("approx f'(1) w/ bw.d.: %f\n", backward_derivative_at(&f, 1, h));
  //
  //  v = InitArray(double, {1, 2, 3, 4, 5});
  //  w = InitArray(double, {2, 3, 4, 5, 6});
  //  format_vector_into(v, v_s);
  //  format_vector_into(w, w_s);
  //  printf("v: %s\n", v_s);
  //  printf("w: %s\n", w_s);
  //
  //  Line *line = least_squares_lin_reg(v, w);
  //  printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);
  //
  //  v = InitArray(double, {1, 2, 3, 4, 5, 6, 7});
  //  w = InitArray(double, {0.5, 3, 2, 3.5, 5, 6, 7.5});
  //
  //  format_vector_into(v, v_s);
  //  format_vector_into(w, w_s);
  //  printf("v: %s\n", v_s);
  //  printf("w: %s\n", w_s);
  //  line = least_squares_lin_reg(v, w);
  //  printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);

  char m_s[256];
  Matrix_double *m = InitMatrixWithSize(double, 8, 8, 0.0);
  put_identity_diagonal(m);
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      m->data[i]->data[j] = (i + 1.0) + j * 3 + (rand() % 12);
    }
  }

  format_matrix_into(m, m_s);
  printf("%s\n", m_s);

  Matrix_double **u_l = put_lu_decomp(m);
  Matrix_double *u = u_l[0];
  Matrix_double *l = u_l[1];

  format_matrix_into(u, m_s);
  printf("%s\n", m_s);
  format_matrix_into(l, m_s);
  printf("%s\n", m_s);

  return 0;
}