int main (int argc, char **argv) { unsigned int n; unsigned int i, j; double **a, *b, **a1, *b1; n = 50; a = JDMdouble_matrix (n, n); a1 = JDMdouble_matrix (n, n); b = JDMdouble_vector (n); b1 = JDMdouble_vector (n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) a[i][j] = a1[i][j] = JDMrandom (); b[i] = b1[i] = JDMrandom (); } if (0 == JDMgauss_jordan (a, b, n)) { for (i = 0; i < n; i++) { double sum = 0; for (j = 0; j < n; j++) sum += a[i][j] * b1[j]; fprintf (stdout, "%e\n", sum - b[i]); } } return 0; }
JDM_Bilinear_Interp_Type *JDM_bilinear_open (double x, double y, double dx, double dy, unsigned int num, double *f_ll, double *f_lr, double *f_ul, double *f_ur) { unsigned int i; JDM_Bilinear_Interp_Type *b; if ((dx == 0.0) || (dy == 0.0) || (num == 0)) { JDMath_Error = JDMATH_INVALID_PARAMETER; return NULL; } b = (JDM_Bilinear_Interp_Type *)_JDMmalloc (sizeof (JDM_Bilinear_Interp_Type), "JDM_bilinear_open"); if (b == NULL) return b; memset ((char *) b, 0, sizeof (JDM_Bilinear_Interp_Type)); if ((NULL == (b->f0 = JDMdouble_vector (num))) || (NULL == (b->f1 = JDMdouble_vector (num))) || (NULL == (b->f2 = JDMdouble_vector (num))) || (NULL == (b->f3 = JDMdouble_vector (num)))) { JDM_bilinear_close (b); return NULL; } b->x = x; b->y = y; b->inv_dx = 1.0 / dx; b->inv_dy = 1.0 / dy; for (i = 0; i < num; i++) { double lr, ll, ul, ur; lr = f_lr[i]; ll = f_ll[i]; ul = f_ul[i]; ur = f_ur[i]; lr -= ll; ur -= ll; ul -= ll; b->f0[i] = ll; b->f1[i] = lr; b->f2[i] = ul; b->f3[i] = (ur - lr - ul); } b->num_values = num; return b; }
double *_JDM_equilibrate (double **a, unsigned int n, double *eq) { unsigned int i; int is_malloced; is_malloced = 0; if (eq == NULL) { eq = JDMdouble_vector (n+1); if (eq == NULL) return eq; is_malloced = 1; } for (i = 0; i < n; i++) { double max = _JDM_nvector_max_abs (a[i], n); if (max == 0) { if (is_malloced) ISIS_FREE (eq); return NULL; } eq[i] = 1.0 / max; } return eq; }
static int pop_linear_system (Linear_System_Type *t) /*{{{*/ { SLang_Array_Type *sl_a=NULL, *sl_b=NULL; double **a=NULL, *b=NULL; SLindex_Type i, j, n, dims[2]; int status = -1; t->a = NULL; t->b = NULL; t->n = 0; if ((-1 == SLang_pop_array_of_type (&sl_b, SLANG_DOUBLE_TYPE)) || (-1 == SLang_pop_array_of_type (&sl_a, SLANG_DOUBLE_TYPE))) goto return_error; n = sl_b->num_elements; if (sl_a->num_elements != (unsigned int) n*n) goto return_error; if ((NULL == (a = JDMdouble_matrix (n, n))) || (NULL == (b = JDMdouble_vector (n)))) goto return_error; memcpy ((char *)b, (char *)sl_b->data, n * sizeof(double)); for (i = 0; i < n; i++) { double *ai = a[i]; if (-1 == SLang_get_array_element (sl_b, &i, &b[i])) goto return_error; dims[0] = i; for (j = 0; j < n; j++) { double aij; dims[1] = j; if (-1 == SLang_get_array_element (sl_a, dims, &aij)) goto return_error; ai[j] = aij; } } t->a = a; t->b = b; t->n = n; status = 0; return_error: SLang_free_array (sl_a); SLang_free_array (sl_b); return status; }