home *** CD-ROM | disk | FTP | other *** search
- expt)
- VEC *a;
- double offset;
- int *expt;
- {
- Real mant, tmp_fctr;
- int i, tmp_expt;
-
- if ( ! a )
- error(E_NULL,"product");
-
- mant = 1.0;
- *expt = 0;
- if ( offset == 0.0 )
- for ( i = 0; i < a->dim; i++ )
- {
- mant *= frexp(a->ve[i],&tmp_expt);
- *expt += tmp_expt;
- if ( ! (i % 10) )
- {
- mant = frexp(mant,&tmp_expt);
- *expt += tmp_expt;
- }
- }
- else
- for ( i = 0; i < a->dim; i++ )
- {
- tmp_fctr = a->ve[i] - offset;
- tmp_fctr += (tmp_fctr > 0.0 ) ? -MACHEPS*offset :
- MACHEPS*offset;
- mant *= frexp(tmp_fctr,&tmp_expt);
- *expt += tmp_expt;
- if ( ! (i % 10) )
- {
- mant = frexp(mant,&tmp_expt);
- *expt += tmp_expt;
- }
- }
-
- mant = frexp(mant,&tmp_expt);
- *expt += tmp_expt;
-
- return mant;
- }
-
- /* product2 -- returns the product of a long list of numbers
- -- answer stored in mant (mantissa) and expt (exponent) */
- static double product2(a,k,expt)
- VEC *a;
- int k; /* entry of a to leave out */
- int *expt;
- {
- Real mant, mu, tmp_fctr;
- int i, tmp_expt;
-
- if ( ! a )
- error(E_NULL,"product2");
- if ( k < 0 || k >= a->dim )
- error(E_BOUNDS,"product2");
-
- mant = 1.0;
- *expt = 0;
- mu = a->ve[k];
- for ( i = 0; i < a->dim; i++ )
- {
- if ( i == k )
- continue;
- tmp_fctr = a->ve[i] - mu;
- tmp_fctr += ( tmp_fctr > 0.0 ) ? -MACHEPS*mu : MACHEPS*mu;
- mant *= frexp(tmp_fctr,&tmp_expt);
- *expt += tmp_expt;
- if ( ! (i % 10) )
- {
- mant = frexp(mant,&tmp_expt);
- *expt += tmp_expt;
- }
- }
- mant = frexp(mant,&tmp_expt);
- *expt += tmp_expt;
-
- return mant;
- }
-
- /* dbl_cmp -- comparison function to pass to qsort() */
- static int dbl_cmp(x,y)
- Real *x, *y;
- {
- Real tmp;
-
- tmp = *x - *y;
- return (tmp > 0 ? 1 : tmp < 0 ? -1: 0);
- }
-
- /* iter_lanczos2 -- lanczos + error estimate for every e-val
- -- uses Cullum & Willoughby approach, Sparse Matrix Proc. 1978
- -- returns multiple e-vals where multiple e-vals may not exist
- -- returns evals vector */
- VEC *iter_lanczos2(ip,evals,err_est)
- ITER *ip; /* ITER structure */
- VEC *evals; /* eigenvalue vector */
- VEC *err_est; /* error estimates of eigenvalues */
- {
- VEC *a;
- static VEC *b=VNULL, *a2=VNULL, *b2=VNULL;
- Real beta, pb_mant, det_mant, det_mant1, det_mant2;
- int i, pb_expt, det_expt, det_expt1, det_expt2;
-
- if ( ! ip )
- error(E_NULL,"iter_lanczos2");
- if ( ! ip->Ax || ! ip->x )
- error(E_NULL,"iter_lanczos2");
- if ( ip->k <= 0 )
- error(E_RANGE,"iter_lanczos2");
-
- a = evals;
- a = v_resize(a,(u_int)ip->k);
- b = v_resize(b,(u_int)(ip->k-1));
- MEM_STAT_REG(b,TYPE_VEC);
-
- iter_lanczos(ip,a,b,&beta,MNULL);
-
- /* printf("# beta =%g\n",beta); */
- pb_mant = 0.0;
- if ( err_est )
- {
- pb_mant = product(b,(double)0.0,&pb_expt);
- /* printf("# pb_mant = %g, pb_expt = %d\n",pb_mant, pb_expt); */
- }
-
- /* printf("# diags =\n"); v_output(a); */
- /* printf("# off diags =\n"); v_output(b); */
- a2 = v_resize(a2,a->dim - 1);
- b2 = v_resize(b2,b->dim - 1);
- MEM_STAT_REG(a2,TYPE_VEC);
- MEM_STAT_REG(b2,TYPE_VEC);
- for ( i = 0; i < a2->dim - 1; i++ )
- {
- a2->ve[i] = a->ve[i+1];
- b2->ve[i] = b->ve[i+1];
- }
- a2->ve[a2->dim-1] = a->ve[a2->dim];
-
- trieig(a,b,MNULL);
-
- /* sort evals as a courtesy */
- qsort((void *)(a->ve),(int)(a->dim),sizeof(Real),(int (*)())dbl_cmp);
-
- /* error estimates */
- if ( err_est )
- {
- err_est = v_resize(err_est,(u_int)ip->k);
-
- trieig(a2,b2,MNULL);
- /* printf("# a =\n"); v_output(a); */
- /* printf("# a2 =\n"); v_output(a2); */
-
- for ( i = 0; i < a->dim; i++ )
- {
- det_mant1 = product2(a,i,&det_expt1);
- det_mant2 = product(a2,(double)a->ve[i],&det_expt2);
- /* rights reserved.
- **
- ** Meschach Library
- **
- ** This Meschach Library is provided "as is" without any express
- ** or implied warranty of any kind with respect to this software.
- ** In particular the authors shall not be liable for any direct,
- ** indirect, special, incidental or consequential damages arising
- ** in any way from use of the software.
- **
- ** Everyone is granted permission to copy, modify and redistribute this
- ** Meschach Library, provided:
- ** 1. All copies contain this copyright notice.
- ** 2. All modified copies shall carry a notice stating who
- ** made the last modification and the date of such modification.
- ** 3. No charge is made for this software or works derived from it.
- ** This clause shall not be construed as constraining other software
- ** distributed on the same medium as this software, nor is a
- ** distribution fee considered a charge.
- **
- ***************************************************************************/
-
-
- /* matop.c 1.3 11/25/87 */
-
-
- #include <stdio.h>
- #include "matrix.h"
-
- static char rcsid[] = "$Id: matop.c,v 1.3 1994/01/13 05:30:28 des Exp $";
-
-
- /* m_add -- matrix addition -- may be in-situ */
- MAT *m_add(mat1,mat2,out)
- MAT *mat1,*mat2,*out;
- {
- u_int m,n,i;
-
- if ( mat1==(MAT *)NULL || mat2==(MAT *)NULL )
- error(E_NULL,"m_add");
- if ( mat1->m != mat2->m || mat1->n != mat2->n )
- error(E_SIZES,"m_add");
- if ( out==(MAT *)NULL || out->m != mat1->m || out->n != mat1->n )
- out = m_resize(out,mat1->m,mat1->n);
- m = mat1->m; n = mat1->n;
- for ( i=0; i<m; i++ )
- {
- __add__(mat1->me[i],mat2->me[i],out->me[i],(int)n);
- /**************************************************
- for ( j=0; j<n; j++ )
- out->me[i][j] = mat1->me[i][j]+mat2->me[i][j];
- **************************************************/
- }
-
- return (out);
- }
-
- /* m_sub -- matrix subtraction -- may be in-situ */
- MAT *m_sub(mat1,mat2,out)
- MAT *mat1,*mat2,*out;
- {
- u_int m,n,i;
-
- if ( mat1==(MAT *)NULL || mat2==(MAT *)NULL )
- error(E_NULL,"m_sub");
- if ( mat1->m != mat2->m || mat1->n != mat2->n )
- e for any direct,
- ** indirect, special, incidental or consequential damages arising
- ** in any way from use of the software.
- **
- ** Everyone is granted permission to copy, modify and redistribute this
- ** Meschach Library, provided:
- ** 1. All copies contain this copyright notice.
- ** 2. All modified copies shall carry a notice stating who
- ** made the last modification and the date of such modification.
- ** 3. No charge is made for this software or works derived from it.
- ** This clause shall not be construed as constraining other software
- ** distributed on the same medium as this software, nor is a
- ** distribution fee considered a charge.
- **
- ***************************************************************************/
-
-
- /*
- Files for matrix computations
-
-