15 return (-zero < a && a < zero) ? 0.0 : a ;
19 if (zero == 0.0)
return a;
20 double *p =
new double[n];
33 if (vs != 3 && vs != 6)
errol;
42 double x =
a[0] * v[0] +
a[1] * v[1] +
a[2] * v[2];
43 double y =
a[3] * v[0] +
a[4] * v[1] +
a[5] * v[2];
44 double z =
a[6] * v[0] +
a[7] * v[1] +
a[8] * v[2];
67 x = point->
x * r[0] + point->
y * r[1] + point->
z * r[2];
68 y = point->
x * r[3] + point->
y * r[4] + point->
z * r[5];
69 z = point->
x * r[6] + point->
y * r[7] + point->
z * r[8];
74 double xx = x * r[0] + y * r[1] + z * r[2];
75 double yy = x * r[3] + y * r[4] + z * r[5];
76 double zz = x * r[6] + y * r[7] + z * r[8];
84 double xx = x * r[0] + y * r[1];
85 double yy = x * r[2] + y * r[3];
96 sprintf (stream,
"% .*e", precision, (absZero != 0.0) ?
give_copy_r2z (
a, absZero) :
a);
104 relzero *= this->give_lenght();
105 return (relzero > abszero ? relzero : abszero);
116 if (newsize <= asize)
return;
119 long* newa =
new long[asize];
121 for (newsize=0; newsize<size; newsize++) *newa++ = *
a++;
149 if (
a && !exta)
delete []
a;
152 shft = size = asize = 0;
160 for (
long i=0; i<size; i++)
161 length +=
a[i] *
a[i];
165 long Lvctr :: give_sum (
void)
const {
long sum = 0;
for (
long i=0; i<size; i++) sum +=
a[i];
return sum; }
179 void Lvctr :: printYourself (
bool force)
const 182 if (size > 20 && !force)
_errorr(
"Count of rows is > 20, to force printing set first parameter as true");
184 fprintf (stdout,
"Long vector [%ld]:\n", size);
186 for (
long i=0; i<size; i++) fprintf (stdout,
"%ld ",
a[i]);
188 fprintf (stdout,
"\n");
197 int numlen = precision+1;
199 ; sprintf (stream,
"%ld",
a[0]); stream += numlen-1;
200 for (
long i=1; i<size; i++) { sprintf (stream,
" %*ld", precision,
a[i]); stream += numlen; }
205 if (zerorest) {
if (size < 0)
errol; }
206 else if (size < 3)
errol;
208 sprintf (stream,
"%*ld %*ld %*ld",
209 precision, size>=1 ?
a[0] : 0,
210 precision, size>=2 ?
a[1] : 0,
211 precision, size>=3 ?
a[2] : 0);
218 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[0], precision, a[5], precision, a[4]);
while (stream[0] !=
'\0') stream++;
219 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[5], precision, a[1], precision, a[3]);
while (stream[0] !=
'\0') stream++;
220 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[4], precision, a[3], precision, a[2]);
224 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
while (stream[0] !=
'\0') stream++;
225 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
while (stream[0] !=
'\0') stream++;
226 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
230 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[0], precision, a[5], precision, a[4]);
231 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[5], precision, a[1], precision, a[3]);
232 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[4], precision, a[3], precision, a[2]);
236 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
237 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
238 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
243 if (zerorest) {
if (size != 0 && size != 6)
errol; }
244 else if (size != 6)
errol;
251 if (zerorest) {
if (size != 0 && size != 6)
errol; }
252 else if (size != 6)
errol;
267 if (newsize <= asize)
return;
270 double* newa =
new double[asize];
272 for (newsize=0; newsize<size; newsize++) *newa++ = *
a++;
301 if (
a && !exta)
delete []
a;
304 shft = size = asize = 0;
312 if (size == 0)
_warningg (
"size = 0 in give_length function");
316 for (
long i=0; i<size; i++)
317 length +=
a[i] *
a[i];
324 for (
long i=0; i<size; i++)
338 this->resize_ignore_vals(6);
354 _errorr (
"size of vectors is not equal to 3");
356 this->resize_ignore_vals(3);
361 a[0] = a1[1] * a2[2] - a2[1] * a1[2];
362 a[1] = a1[2] * a2[0] - a2[2] * a1[0];
363 a[2] = a1[0] * a2[1] - a2[0] * a1[1];
373 this->beCopyOf(psrc, m);
378 for (
long i=0; i<m; i++)
389 for (
long i=0; i<this->size; i++)
390 prd +=
a[i] * v.
a[i];
404 for (
long i=0; i<size; i++)
411 for (
long i=0; i<size; i++)
433 if ( size != 6 )
_errorr (
"size of vectors is not equal to 6");
437 aa[0] = rot(0,0)*rot(0,0) *
a[0] + rot(0,1)*rot(0,1) *
a[1] + rot(0,2)*rot(0,2) *
a[2] + 2*rot(0,0)*rot(0,1) *
a[5] + 2*rot(0,0)*rot(0,2) *
a[4] + 2*rot(0,1)*rot(0,2) *
a[3];
438 aa[1] = rot(1,0)*rot(1,0) * a[0] + rot(1,1)*rot(1,1) * a[1] + rot(1,2)*rot(1,2) * a[2] + 2*rot(1,0)*rot(1,1) * a[5] + 2*rot(1,0)*rot(1,2) * a[4] + 2*rot(1,1)*rot(1,2) * a[3];
439 aa[2] = rot(2,0)*rot(2,0) * a[0] + rot(2,1)*rot(2,1) * a[1] + rot(2,2)*rot(2,2) * a[2] + 2*rot(2,0)*rot(2,1) * a[5] + 2*rot(2,0)*rot(2,2) * a[4] + 2*rot(2,1)*rot(2,2) * a[3];
441 aa[5] = rot(0,0)*rot(1,0) * a[0] + rot(0,1)*rot(1,1) * a[1] + rot(0,2)*rot(1,2) * a[2] + (rot(0,0)*rot(1,1) + rot(0,1)*rot(1,0)) * a[5] + (rot(0,1)*rot(1,2) + rot(0,2)*rot(1,1)) * a[3] + (rot(0,0)*rot(1,2) + rot(0,2)*rot(1,0)) * a[4];
442 aa[3] = rot(1,0)*rot(2,0) * a[0] + rot(1,1)*rot(2,1) * a[1] + rot(1,2)*rot(2,2) * a[2] + (rot(1,0)*rot(2,1) + rot(1,1)*rot(2,0)) * a[5] + (rot(1,1)*rot(2,2) + rot(1,2)*rot(2,1)) * a[3] + (rot(1,0)*rot(2,2) + rot(1,2)*rot(2,0)) * a[4];
443 aa[4] = rot(0,0)*rot(2,0) * a[0] + rot(0,1)*rot(2,1) * a[1] + rot(0,2)*rot(2,2) * a[2] + (rot(0,0)*rot(2,1) + rot(0,1)*rot(2,0)) * a[5] + (rot(0,1)*rot(2,2) + rot(0,2)*rot(2,1)) * a[3] + (rot(0,0)*rot(2,2) + rot(0,2)*rot(2,0)) * a[4];
462 if ( size != 6 )
_errorr (
"size of vectors is not equal to 6");
464 double c = cos(alpha);
465 double s = sin(alpha);
469 aa[0] = c*c *
a[0] + s*s *
a[1] - 2*c*s *
a[5] ;
470 aa[1] = s*s * a[0] + c*c * a[1] + 2*s*c * a[5] ;
473 aa[5] = c*s * a[0] - s*c * a[1] + (c*c - s*s) * a[5] ;
474 aa[3] = c * a[3] + s * a[4];
475 aa[4] = -s * a[3] + c * a[4];
486 double length = this->give_lenght();
497 norm2 += (*p) * (*p);
547 void Dvctr :: printYourself (
bool force)
const 550 if (size > 20 && !force)
_errorr(
"Count of rows is > 20, to force printing set first parameter as true");
552 fprintf (stdout,
"Double vector [%ld]:\n", size);
554 for (
long i=0; i<size; i++) fprintf (stdout,
"% .*e ",
PYP,
a[i]);
556 fprintf (stdout,
"\n");
570 ; sprintf (stream,
"% .*e", precision, p[0]); stream += numlen-1;
571 for (
long i=1; i<size; i++) { sprintf (stream,
" % .*e", precision, p[i]); stream += numlen; }
573 if (p !=
a)
delete [] p;
578 if (zerorest) {
if (size < 0)
errol; }
579 else if (size < 3)
errol;
584 sprintf (stream,
"% .*e % .*e % .*e",
585 precision, size>=1 ? p[0] : 0.0,
586 precision, size>=2 ? p[1] : 0.0,
587 precision, size>=3 ? p[2] : 0.0);
589 if (p !=
a)
delete [] p;
597 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[1], precision, a[2]);
598 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[3], precision, a[4], precision, a[5]);
599 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[6], precision, a[7], precision, a[8]);
603 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[5], precision, a[4]);
while (stream[0] !=
'\0') stream++;
604 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[5], precision, a[1], precision, a[3]);
while (stream[0] !=
'\0') stream++;
605 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[4], precision, a[3], precision, a[2]);
609 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[5], precision, a[4]);
610 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[5], precision, a[1], precision, a[3]);
611 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[4], precision, a[3], precision, a[2]);
616 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
while (stream[0] !=
'\0') stream++;
617 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
while (stream[0] !=
'\0') stream++;
618 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
622 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
623 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
624 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
631 if (zerorest) {
if (size != 0 && size != 6)
errol; }
632 else if (size != 6)
errol;
640 if (p !=
a)
delete [] p;
644 if (zerorest) {
if (size != 0 && size != 6)
errol; }
645 else if (size != 6)
errol;
653 if (p !=
a)
delete [] p;
698 if (crow == r && ccol == c)
return;
702 if (asize < crow*ccol) {
715 void Lmtrx :: printYourself (
bool force)
const 718 if (crow > 50)
_warningg(
"count of rows is > 50");
719 if (ccol > 50)
_warningg(
"count of collumns is > 50");
721 fprintf (stdout,
"Long matrix [%ld,%ld]:\n", crow, ccol);
724 for (i=0; i<crow; i++) {
725 for (j=0; j<ccol; j++)
726 fprintf (stdout,
"%ld",
a[i*ccol + j]);
728 fprintf (stdout,
"\n");
744 if (crow == r && ccol == c)
return;
748 if (asize < crow*ccol) {
751 a =
new double[asize];
765 this->resize_ignore_vals(3,3);
771 a[5] =
a[7] = asrc[3];
772 a[2] =
a[6] = asrc[4];
773 a[1] =
a[3] = asrc[5];
782 for (i=0; i<crow; i++)
783 for (j=0; j<ccol; j++)
784 a[i*ccol + j] = asrc[j*ccol + i];
800 for (i=0; i<crow; i++)
801 for (j=0; j<ccol; j++)
802 for (k=0; k<ccr; k++)
803 a[i*ccol + j] += aA[i*ccr+k] * aB[k*ccol+j];
812 this->beCopyOf(mtrxXthis);
820 this->beCopyOf(thisXmtrx);
830 if (crow == ccol && ccol == 2)
return a[0] *
a[3] -
a[1] *
a[2];
831 else if (crow == ccol && ccol == 3)
return a[0] * a[4] * a[8] + a[3] * a[7] * a[2] +
832 a[6] * a[1] * a[5] - a[6] * a[4] * a[2] -
833 a[7] * a[5] * a[0] - a[8] * a[3] * a[1] ;
834 else _errorr3(
"cannot compute determinant of matrix %ld x %ld", crow, ccol);
845 if (crow != ccol)
_errorr3 (
"matrix is not square, %ld != %ld", crow, ccol);
854 for (i=0; i<crow-1; i++) {
858 for (j=i+1; j<crow; j++)
859 if (fabs(
a[j*ccol+i]) > fabs(
a[maxrow*ccol+i]))
863 if (fabs(
a[maxrow*ccol+i]) < 1.0e-15)
868 for (j=i; j<crow; j++) {
870 a[i*ccol+j] =
a[maxrow*ccol+j];
871 a[maxrow*ccol+j] = tmp;
880 for (j=i+1; j<crow; j++) {
881 tmp =
a[j*ccol+i] /
a[i*ccol+i];
883 for (k=i; k<crow; k++)
884 a[j*ccol+k] -=
a[i*ccol+k] * tmp;
891 if (fabs(
a[crow*ccol-1]) < 1.0e-15)
895 for (i=crow-1; i>=0; i--) {
897 for (j=i+1; j<crow; j++)
898 tmp +=
a[i*ccol+j] * x[j];
900 x[i] = (x[i] - tmp) /
a[i*ccol+i];
914 if (crow != ccol)
_errorr3 (
"matrix is not square, %ld != %ld", crow, ccol);
915 if (crow != rhs[0].give_size())
_errorr3 (
"matrix and rhs dimension differs, %ld != %ld", crow, rhs[0].give_size());
918 int i, j, k, n, maxrow;
921 for (n=0; n<nrhs; n++) x[n].beCopyOf(rhs[n]);
923 for (i=0; i<crow-1; i++) {
927 for (j=i+1; j<crow; j++)
928 if (fabs(
a[j*ccol+i]) > fabs(
a[maxrow*ccol+i]))
932 if (fabs(
a[maxrow*ccol+i]) < 1.0
e-15)
937 for (j=i; j<crow; j++) {
939 a[i*ccol+j] =
a[maxrow*ccol+j];
940 a[maxrow*ccol+j] = tmp;
943 for (n=0; n<nrhs; n++) {
945 x[n][i] = x[n][maxrow];
951 for (j=i+1; j<crow; j++) {
952 tmp =
a[j*ccol+i] /
a[i*ccol+i];
954 for (k=i; k<crow; k++)
955 a[j*ccol+k] -=
a[i*ccol+k] * tmp;
957 for (n=0; n<nrhs; n++)
958 x[n][j] -= x[n][i] * tmp;
963 if (fabs(
a[crow*ccol-1]) < 1.0
e-15)
967 for (i=crow-1; i>=0; i--) {
968 for (n=0; n<nrhs; n++) {
970 for (j=i+1; j<crow; j++)
971 tmp +=
a[i*ccol+j] * x[n][j];
973 x[n][i] = (x[n][i] - tmp) /
a[i*ccol+i];
986 void Dmtrx :: printYourself (
bool force)
const 989 if (crow > 10)
_errorr(
"count of rows is > 10");
990 if (ccol > 10)
_errorr(
"count of collumns is > 10");
992 fprintf (stdout,
"Double matrix [%ld,%ld]:\n", crow, ccol);
995 for (i=0; i<crow; i++) {
996 for (j=0; j<ccol; j++)
997 fprintf (stdout,
"% .*e ",
PYP,
a[i*ccol + j]);
999 fprintf (stdout,
"\n");
1014 if (zerorest) {
if (! ((crow == 0 && ccol == 0) || (crow == 3 && ccol == 3)) )
errol; }
1015 else if (crow != 3 || ccol != 3)
errol;
1023 if (p !=
a)
delete [] p;
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
double give_dotproduct(const Dvctr &v) const
void print(char *stream, int precision, double absZero=0.0) const
void realloc(long newsize)
reallocate up receiver
void be_mean_of(const Dmtrx *src)
virtual long give_size(void) const
double compute_squared_norm(void) const
virtual void print(char *stream, int precision, double absZero=0.0) const
void print(char *stream, int precision, double absZero=0.0) const
void pprint_tensor(FILE *stream, int precision, const double *a)
double give_lenght(void) const
void resize_ignore_vals(long r, long c)
print yourself
#define array(MAT, ROWS, COLS, ROW, COL)
void rotate(Dvctr *v) const
void pprint_symtensor(char *stream, int precision, const long *a)
void pprint_tensor_zero(char *stream, int precision)
void beRotatedBy2d(const double *r)
Receiver will be rotated by 2d matrix 'rot'. this = rot . this.
long give_ccols(void) const
#define NUM_DIGITS_IN_PRINTED_EXPONENT
void beRotatedBy(const double *r)
Receiver will be rotated by matrix 'rot'. this = rot . this.
long give_sum(void) const
int length_printed_tensor(int precision) const
Lvctr * assign_array(long *array, long s)
void be_tnsr(const Dmtrx &src)
void sbt(const Dvctr &src)
double give_lenght(void) const
void beRotatedPoint(const Dmtrx *rot, const PoinT *point)
Receiver will be point 'point' rotated by matrix 'rot'. this = rot . point.
void be_tnsr(const Dvctr &src)
double give_determinant(void) const
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
Structs Elem3D, PoinT and VectoR; classes Array, Array1d, Xscal, Dscal, Xvctr, Lvctr, Dvctr, Xmtrx, Lmtrx and Dmtrx.
long give_number_of_zeros(void) const
long give_number_of_nonzeros(void) const
void tmsRightBy(const Dmtrx &src)
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
double * give_ptr2val(long r=0, long c=0)
void tmsLeftBy(const Dmtrx &src)
void tnsrRotWith(const Dmtrx &rot)
this = rot * this * rot^transp
int length_printed_vector(int precision) const
void print_tensor(FILE *stream, int precision, double absZero, bool zerorest) const
print yourself
int length_printed_vector(int precision) const
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
#define _errorr3(_1, _2, _3)
void pprint_symtensor_zeroL(char *stream, int precision)
double give_zero(double abszero, double relzero) const
void be_mtrxMmtrx(const Dmtrx &A, const Dmtrx &B)
void tnsrRotAxisZangle(double a)
rotate coord system around axis z by angle
int length_printed(int precision) const
void round2zero (double zero, double absZero);
double give_sum(void) const
void realloc(long newsize)
reallocate up receiver
double give_copy_r2z(double a, double zero)
bool GaussSolve(Dvctr &x, const Dvctr &rhs)
gaussian eliminatio
Dvctr * assign_array(double *array, long s)
long give_crows(void) const
double * give_ptr2val(long i=0)
return pointer to
void add(const Dvctr &src)
void be_transposition(const Dmtrx &src)
int length_printed(int precision) const
void resize_ignore_vals(long r, long c)
int length_printed_tensor(int precision) const
void addtms(const Dvctr &src, double tms)
void be_vectproduct(const Dvctr &v1, const Dvctr &v2)