3 * Copyright (C) 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <gsl/gsl_errno.h>
22 #include <gsl/gsl_multifit.h>
24 gsl_multifit_linear_workspace *
25 gsl_multifit_linear_alloc (size_t n, size_t p)
27 gsl_multifit_linear_workspace *w;
29 w = (gsl_multifit_linear_workspace *)
30 malloc (sizeof (gsl_multifit_linear_workspace));
34 GSL_ERROR_VAL ("failed to allocate space for multifit_linear struct",
38 w->n = n; /* number of observations */
39 w->p = p; /* number of parameters */
41 w->A = gsl_matrix_alloc (n, p);
46 GSL_ERROR_VAL ("failed to allocate space for A", GSL_ENOMEM, 0);
49 w->Q = gsl_matrix_alloc (p, p);
53 gsl_matrix_free (w->A);
55 GSL_ERROR_VAL ("failed to allocate space for Q", GSL_ENOMEM, 0);
58 w->QSI = gsl_matrix_alloc (p, p);
62 gsl_matrix_free (w->Q);
63 gsl_matrix_free (w->A);
65 GSL_ERROR_VAL ("failed to allocate space for QSI", GSL_ENOMEM, 0);
68 w->S = gsl_vector_alloc (p);
72 gsl_matrix_free (w->QSI);
73 gsl_matrix_free (w->Q);
74 gsl_matrix_free (w->A);
76 GSL_ERROR_VAL ("failed to allocate space for S", GSL_ENOMEM, 0);
79 w->t = gsl_vector_alloc (n);
83 gsl_vector_free (w->S);
84 gsl_matrix_free (w->QSI);
85 gsl_matrix_free (w->Q);
86 gsl_matrix_free (w->A);
88 GSL_ERROR_VAL ("failed to allocate space for t", GSL_ENOMEM, 0);
91 w->xt = gsl_vector_calloc (p);
95 gsl_vector_free (w->t);
96 gsl_vector_free (w->S);
97 gsl_matrix_free (w->QSI);
98 gsl_matrix_free (w->Q);
99 gsl_matrix_free (w->A);
101 GSL_ERROR_VAL ("failed to allocate space for xt", GSL_ENOMEM, 0);
104 w->D = gsl_vector_calloc (p);
108 gsl_vector_free (w->D);
109 gsl_vector_free (w->t);
110 gsl_vector_free (w->S);
111 gsl_matrix_free (w->QSI);
112 gsl_matrix_free (w->Q);
113 gsl_matrix_free (w->A);
115 GSL_ERROR_VAL ("failed to allocate space for xt", GSL_ENOMEM, 0);
122 gsl_multifit_linear_free (gsl_multifit_linear_workspace * work)
124 gsl_matrix_free (work->A);
125 gsl_matrix_free (work->Q);
126 gsl_matrix_free (work->QSI);
127 gsl_vector_free (work->S);
128 gsl_vector_free (work->t);
129 gsl_vector_free (work->xt);
130 gsl_vector_free (work->D);