示例
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 | #include <stdio.h> #include <math.h> #include "kipl.h" int main() { int data_n = 11; float *data_x = (float *)malloc(data_n * sizeof(float)); float *data_y = (float *)malloc(data_n * sizeof(float)); for (int i = 0; i < data_n; i++) { data_x[i] = (float)(i) / (data_n - 1); data_y[i] = sin(15.0 * data_x[i]); } int test_n = 2 * data_n - 1; float test_x[test_n]; float test_y[test_n]; for (int i = 0; i < test_n; i++) { test_x[i] = (float)(i) / (test_n - 1); test_y[i] = sin(15.0 * test_x[i]); } float b[data_n], cscoef[4 * data_n]; KIPL_Csint(data_n, data_x, data_y, cscoef); int nintv = data_n - 1; for (int i = 0; i < test_n; i++) { float y; float x = test_x[i]; y = KIPL_Csval(x, nintv, data_x, cscoef); printf("%f %f\n", x, y); } int nintv = data_n - 1; int ideriv = 0; float derValue[test_n]; KIPL_Cs1gd(ideriv, test_n, test_x, nintv, data_x, cscoef, derValue); free(data_x); free(data_y); return 0; } |
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 | #include <stdio.h> #include <math.h> #include "kipl.h" int main() { int data_n = 11; float *data_x = (float *)malloc(data_n * sizeof(float)); float *data_y = (float *)malloc(data_n * sizeof(float)); for (int i = 0; i < data_n; i++) { data_x[i] = (float)(i) / (data_n - 1); data_y[i] = sin(15.0 * data_x[i]); } int test_n = 2 * data_n - 1; float test_x[test_n]; float test_y[test_n]; for (int i = 0; i < test_n; i++) { test_x[i] = (float)(i) / (test_n - 1); test_y[i] = sin(15.0 * test_x[i]); } float b[data_n], cscoef[4 * data_n]; float weight[data_n]; float smpar = data_n; for (int i = 0; i < data_n; i++) { weight[i] = 0.1; } KIPL_Cssmh(data_n, data_x, data_y, weight, smpar, cscoef); int nintv = data_n - 1; for (int i = 0; i < test_n; i++) { float y; float x = test_x[i]; y = KIPL_Csval(x, nintv, data_x, cscoef); printf("%f %f\n", x, y); } free(data_x); free(data_y); return 0; } |
父主题: 三次样条函数