format
This commit is contained in:
parent
add2520e49
commit
0ce79392c3
BIN
lib/lizfcm.a
BIN
lib/lizfcm.a
Binary file not shown.
114
test/main.c
114
test/main.c
@ -5,71 +5,69 @@
|
|||||||
double f(double x) { return (x - 1) / (x + 1); }
|
double f(double x) { return (x - 1) / (x + 1); }
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("Basic Routines\n");
|
printf("Basic Routines\n");
|
||||||
printf("smaceps(): %.10e\n", smaceps());
|
printf("smaceps(): %.10e\n", smaceps());
|
||||||
printf("dmaceps(): %.10e\n", dmaceps());
|
printf("dmaceps(): %.10e\n", dmaceps());
|
||||||
printf("========\n");
|
printf("========\n");
|
||||||
|
|
||||||
Array_double *v = InitArray(double, {3, 1, -4, 1, 5, -9, 3});
|
|
||||||
char v_s[256];
|
|
||||||
strcpy(v_s, "");
|
|
||||||
format_vector_into(v, v_s);
|
|
||||||
|
|
||||||
Array_double *w = InitArray(double, {-2, 7, 1, -8, -2, 8, 5});
|
Array_double *v = InitArray(double, {3, 1, -4, 1, 5, -9, 3});
|
||||||
char w_s[256];
|
char v_s[256];
|
||||||
strcpy(w_s, "");
|
strcpy(v_s, "");
|
||||||
format_vector_into(w, w_s);
|
format_vector_into(v, v_s);
|
||||||
|
|
||||||
printf("Norm, Distance\n");
|
Array_double *w = InitArray(double, {-2, 7, 1, -8, -2, 8, 5});
|
||||||
printf("v: %s", v_s);
|
char w_s[256];
|
||||||
printf("w: %s", w_s);
|
strcpy(w_s, "");
|
||||||
printf("l1_norm(v): %f\n", l1_norm(v));
|
format_vector_into(w, w_s);
|
||||||
printf("l2_norm(v): %f\n", l2_norm(v));
|
|
||||||
printf("linf_norm(v): %f\n", linf_norm(v));
|
printf("Norm, Distance\n");
|
||||||
printf("l1_dist(v, w): %f\n", l1_distance(v, w));
|
printf("v: %s", v_s);
|
||||||
printf("l2_dist(v, w): %f\n", l2_distance(v, w));
|
printf("w: %s", w_s);
|
||||||
printf("linf_dist(v, w): %f\n", linf_distance(v, w));
|
printf("l1_norm(v): %f\n", l1_norm(v));
|
||||||
printf("========\n");
|
printf("l2_norm(v): %f\n", l2_norm(v));
|
||||||
|
printf("linf_norm(v): %f\n", linf_norm(v));
|
||||||
double h = 0.001;
|
printf("l1_dist(v, w): %f\n", l1_distance(v, w));
|
||||||
printf("Derivative Approxs\n");
|
printf("l2_dist(v, w): %f\n", l2_distance(v, w));
|
||||||
printf("f(x) = (x-1)/(x+1)\n");
|
printf("linf_dist(v, w): %f\n", linf_distance(v, w));
|
||||||
printf("approx f'(1) w/ c.d.: %f\n", central_derivative_at(&f, 1, h));
|
printf("========\n");
|
||||||
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));
|
double h = 0.001;
|
||||||
printf("========\n");
|
printf("Derivative Approxs\n");
|
||||||
|
printf("f(x) = (x-1)/(x+1)\n");
|
||||||
v = InitArray(double, {1, 2, 3, 4, 5});
|
printf("approx f'(1) w/ c.d.: %f\n", central_derivative_at(&f, 1, h));
|
||||||
strcpy(v_s, "");
|
printf("approx f'(1) w/ fw.d.: %f\n", forward_derivative_at(&f, 1, h));
|
||||||
format_vector_into(v, v_s);
|
printf("approx f'(1) w/ bw.d.: %f\n", backward_derivative_at(&f, 1, h));
|
||||||
w = InitArray(double, {2, 3, 4, 5, 6});
|
printf("========\n");
|
||||||
strcpy(w_s, "");
|
|
||||||
format_vector_into(w, w_s);
|
v = InitArray(double, {1, 2, 3, 4, 5});
|
||||||
Line *line = least_squares_lin_reg(v, w);
|
strcpy(v_s, "");
|
||||||
printf("Least Squares\n");
|
format_vector_into(v, v_s);
|
||||||
printf("v: %s", v_s);
|
w = InitArray(double, {2, 3, 4, 5, 6});
|
||||||
printf("w: %s", w_s);
|
strcpy(w_s, "");
|
||||||
printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);
|
format_vector_into(w, w_s);
|
||||||
v = InitArray(double, {1, 2, 3, 4, 5, 6, 7});
|
Line *line = least_squares_lin_reg(v, w);
|
||||||
strcpy(v_s, "");
|
printf("Least Squares\n");
|
||||||
format_vector_into(v, v_s);
|
printf("v: %s", v_s);
|
||||||
w = InitArray(double, {0.5, 3, 2, 3.5, 5, 6, 7.5});
|
printf("w: %s", w_s);
|
||||||
strcpy(w_s, "");
|
printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);
|
||||||
format_vector_into(w, w_s);
|
v = InitArray(double, {1, 2, 3, 4, 5, 6, 7});
|
||||||
printf("v: %s", v_s);
|
strcpy(v_s, "");
|
||||||
printf("w: %s", w_s);
|
format_vector_into(v, v_s);
|
||||||
line = least_squares_lin_reg(v, w);
|
w = InitArray(double, {0.5, 3, 2, 3.5, 5, 6, 7.5});
|
||||||
printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);
|
strcpy(w_s, "");
|
||||||
printf("========\n");
|
format_vector_into(w, w_s);
|
||||||
|
printf("v: %s", v_s);
|
||||||
|
printf("w: %s", w_s);
|
||||||
|
line = least_squares_lin_reg(v, w);
|
||||||
|
printf("least_squares_lin_reg(v, w): (%f)x + %f\n", line->m, line->a);
|
||||||
|
printf("========\n");
|
||||||
|
|
||||||
|
|
||||||
printf("LU Decomp\n");
|
printf("LU Decomp\n");
|
||||||
char m_s[2048];
|
char m_s[2048];
|
||||||
Matrix_double *m = InitMatrixWithSize(double, 8, 8, 0.0);
|
Matrix_double *m = InitMatrixWithSize(double, 8, 8, 0.0);
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int j = 0; j < 8; j++) {
|
for (int j = 0; j < 8; j++)
|
||||||
m->data[i]->data[j] = (i + 1.0) + j * 3 + (rand() % 12);
|
m->data[i]->data[j] = (i + 1.0) + j * 3 + (rand() % 12);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
format_matrix_into(m, m_s);
|
format_matrix_into(m, m_s);
|
||||||
printf("m = %s", m_s);
|
printf("m = %s", m_s);
|
||||||
|
Loading…
Reference in New Issue
Block a user