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];
79 sprintf (stream,
"% .*e", precision, (absZero != 0.0) ?
give_copy_r2z (
a, absZero) :
a);
88 return (relzero > abszero ? relzero : abszero);
99 if (newsize <=
asize)
return;
102 long* newa =
new long[
asize];
104 for (newsize=0; newsize<
size; newsize++) *newa++ = *
a++;
132 if (
a && !
exta)
delete []
a;
143 for (
long i=0; i<
size; i++)
144 length +=
a[i] *
a[i];
162 void Lvctr :: printYourself (
bool force)
const
165 if (
size > 20 && !force)
_errorr(
"Count of rows is > 20, to force printing set first parameter as true");
167 fprintf (stdout,
"Long vector [%ld]:\n",
size);
169 for (
long i=0; i<
size; i++) fprintf (stdout,
"%ld ",
a[i]);
171 fprintf (stdout,
"\n");
180 int numlen = precision+1;
182 ; sprintf (stream,
"%ld",
a[0]); stream += numlen-1;
183 for (
long i=1; i<
size; i++) { sprintf (stream,
" %*ld", precision,
a[i]); stream += numlen; }
188 if (zerorest) {
if (size < 0)
errol; }
189 else if (size < 3)
errol;
191 sprintf (stream,
"%*ld %*ld %*ld",
192 precision, size>=1 ?
a[0] : 0,
193 precision, size>=2 ?
a[1] : 0,
194 precision, size>=3 ?
a[2] : 0);
201 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[0], precision, a[5], precision, a[4]);
while (stream[0] !=
'\0') stream++;
202 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[5], precision, a[1], precision, a[3]);
while (stream[0] !=
'\0') stream++;
203 sprintf (stream,
"%*ld %*ld %*ld\n", precision, a[4], precision, a[3], precision, a[2]);
207 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
while (stream[0] !=
'\0') stream++;
208 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
while (stream[0] !=
'\0') stream++;
209 sprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
213 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[0], precision, a[5], precision, a[4]);
214 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[5], precision, a[1], precision, a[3]);
215 fprintf (stream,
"%*ld %*ld %*ld\n", precision, a[4], precision, a[3], precision, a[2]);
219 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
220 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
221 fprintf (stream,
"%*d %*d %*d\n", precision, 0, precision, 0, precision, 0);
226 if (zerorest) {
if (size != 0 && size != 6)
errol; }
227 else if (size != 6)
errol;
234 if (zerorest) {
if (size != 0 && size != 6)
errol; }
235 else if (size != 6)
errol;
250 if (newsize <=
asize)
return;
253 double* newa =
new double[
asize];
255 for (newsize=0; newsize<
size; newsize++) *newa++ = *
a++;
284 if (
a && !
exta)
delete []
a;
295 if (size == 0)
_warningg (
"size = 0 in give_length function");
299 for (
long i=0; i<
size; i++)
300 length +=
a[i] *
a[i];
307 for (
long i=0; i<
size; i++)
337 _errorr (
"size of vectors is not equal to 3");
344 a[0] = a1[1] * a2[2] - a2[1] * a1[2];
345 a[1] = a1[2] * a2[0] - a2[2] * a1[0];
346 a[2] = a1[0] * a2[1] - a2[0] * a1[1];
361 for (
long i=0; i<m; i++)
372 for (
long i=0; i<this->
size; i++)
373 prd +=
a[i] * v.
a[i];
387 for (
long i=0; i<
size; i++)
394 for (
long i=0; i<
size; i++)
416 if ( size != 6 )
_errorr (
"size of vectors is not equal to 6");
420 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];
421 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];
422 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];
424 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];
425 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];
426 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];
445 if ( size != 6 )
_errorr (
"size of vectors is not equal to 6");
447 double c = cos(alpha);
448 double s = sin(alpha);
452 aa[0] = c*c *
a[0] + s*s *
a[1] - 2*c*s *
a[5] ;
453 aa[1] = s*s * a[0] + c*c * a[1] + 2*s*c * a[5] ;
456 aa[5] = c*s * a[0] - s*c * a[1] + (c*c - s*s) * a[5] ;
457 aa[3] = c * a[3] + s * a[4];
458 aa[4] = -s * a[3] + c * a[4];
516 void Dvctr :: printYourself (
bool force)
const
519 if (size > 20 && !force)
_errorr(
"Count of rows is > 20, to force printing set first parameter as true");
521 fprintf (stdout,
"Double vector [%ld]:\n", size);
523 for (
long i=0; i<
size; i++) fprintf (stdout,
"% .*e ",
PYP,
a[i]);
525 fprintf (stdout,
"\n");
539 ; sprintf (stream,
"% .*e", precision, p[0]); stream += numlen-1;
540 for (
long i=1; i<
size; i++) { sprintf (stream,
" % .*e", precision, p[i]); stream += numlen; }
542 if (p !=
a)
delete [] p;
547 if (zerorest) {
if (size < 0)
errol; }
548 else if (size < 3)
errol;
553 sprintf (stream,
"% .*e % .*e % .*e",
554 precision, size>=1 ? p[0] : 0.0,
555 precision, size>=2 ? p[1] : 0.0,
556 precision, size>=3 ? p[2] : 0.0);
558 if (p !=
a)
delete [] p;
566 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[1], precision, a[2]);
567 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[3], precision, a[4], precision, a[5]);
568 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[6], precision, a[7], precision, a[8]);
572 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[5], precision, a[4]);
while (stream[0] !=
'\0') stream++;
573 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[5], precision, a[1], precision, a[3]);
while (stream[0] !=
'\0') stream++;
574 sprintf (stream,
"% .*e % .*e % .*e\n", precision, a[4], precision, a[3], precision, a[2]);
578 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[0], precision, a[5], precision, a[4]);
579 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[5], precision, a[1], precision, a[3]);
580 fprintf (stream,
"% .*e % .*e % .*e\n", precision, a[4], precision, a[3], precision, a[2]);
585 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
while (stream[0] !=
'\0') stream++;
586 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
while (stream[0] !=
'\0') stream++;
587 sprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
591 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
592 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
593 fprintf (stream,
"% .*e % .*e % .*e\n", precision, 0.0, precision, 0.0, precision, 0.0);
600 if (zerorest) {
if (size != 0 && size != 6)
errol; }
601 else if (size != 6)
errol;
609 if (p !=
a)
delete [] p;
613 if (zerorest) {
if (size != 0 && size != 6)
errol; }
614 else if (size != 6)
errol;
622 if (p !=
a)
delete [] p;
684 void Lmtrx :: printYourself (
bool force)
const
690 fprintf (stdout,
"Long matrix [%ld,%ld]:\n",
crow,
ccol);
693 for (i=0; i<
crow; i++) {
694 for (j=0; j<
ccol; j++)
695 fprintf (stdout,
"%ld",
a[i*ccol + j]);
697 fprintf (stdout,
"\n");
713 if (crow == r &&
ccol == c)
return;
740 a[5] =
a[7] = asrc[3];
741 a[2] =
a[6] = asrc[4];
742 a[1] =
a[3] = asrc[5];
751 for (i=0; i<
crow; i++)
752 for (j=0; j<
ccol; j++)
753 a[i*ccol + j] = asrc[j*ccol + i];
769 for (i=0; i<
crow; i++)
770 for (j=0; j<
ccol; j++)
771 for (k=0; k<ccr; k++)
772 a[i*ccol + j] += aA[i*ccr+k] * aB[k*ccol+j];
799 if (crow ==
ccol &&
ccol == 2)
return a[0] *
a[3] -
a[1] *
a[2];
800 else if (crow ==
ccol &&
ccol == 3)
return a[0] * a[4] * a[8] + a[3] * a[7] * a[2] +
801 a[6] * a[1] * a[5] - a[6] * a[4] * a[2] -
802 a[7] * a[5] * a[0] - a[8] * a[3] * a[1] ;
803 else _errorr3(
"cannot compute determinant of matrix %ld x %ld", crow,
ccol);
814 if (crow !=
ccol)
_errorr3 (
"matrix is not square, %ld != %ld", crow,
ccol);
823 for (i=0; i<crow-1; i++) {
827 for (j=i+1; j<
crow; j++)
828 if (fabs(
a[j*
ccol+i]) > fabs(
a[maxrow*
ccol+i]))
832 if (fabs(
a[maxrow*
ccol+i]) < 1.0e-15)
837 for (j=i; j<
crow; j++) {
840 a[maxrow*
ccol+j] = tmp;
849 for (j=i+1; j<
crow; j++) {
852 for (k=i; k<
crow; k++)
860 if (fabs(
a[crow*
ccol-1]) < 1.0e-15)
864 for (i=crow-1; i>=0; i--) {
866 for (j=i+1; j<
crow; j++)
867 tmp +=
a[i*
ccol+j] * x[j];
869 x[i] = (x[i] - tmp) /
a[i*
ccol+i];
883 if (crow !=
ccol)
_errorr3 (
"matrix is not square, %ld != %ld", crow,
ccol);
884 if (crow != rhs[0].give_size())
_errorr3 (
"matrix and rhs dimension differs, %ld != %ld", crow, rhs[0].give_size());
887 int i, j, k, n, maxrow;
890 for (n=0; n<nrhs; n++) x[n].
beCopyOf(rhs[n]);
892 for (i=0; i<crow-1; i++) {
896 for (j=i+1; j<
crow; j++)
897 if (fabs(
a[j*
ccol+i]) > fabs(
a[maxrow*
ccol+i]))
901 if (fabs(
a[maxrow*
ccol+i]) < 1.0e-15)
906 for (j=i; j<
crow; j++) {
909 a[maxrow*
ccol+j] = tmp;
912 for (n=0; n<nrhs; n++) {
914 x[n][i] = x[n][maxrow];
920 for (j=i+1; j<
crow; j++) {
923 for (k=i; k<
crow; k++)
926 for (n=0; n<nrhs; n++)
927 x[n][j] -= x[n][i] * tmp;
932 if (fabs(
a[crow*
ccol-1]) < 1.0e-15)
936 for (i=crow-1; i>=0; i--) {
937 for (n=0; n<nrhs; n++) {
939 for (j=i+1; j<
crow; j++)
940 tmp +=
a[i*
ccol+j] * x[n][j];
942 x[n][i] = (x[n][i] - tmp) /
a[i*
ccol+i];
955 void Dmtrx :: printYourself (
bool force)
const
958 if (crow > 10)
_errorr(
"count of rows is > 10");
959 if (
ccol > 10)
_errorr(
"count of collumns is > 10");
961 fprintf (stdout,
"Double matrix [%ld,%ld]:\n", crow,
ccol);
964 for (i=0; i<
crow; i++) {
965 for (j=0; j<
ccol; j++)
966 fprintf (stdout,
"% .*e ",
PYP,
a[i*ccol + j]);
968 fprintf (stdout,
"\n");
983 if (zerorest) {
if (! ((crow == 0 &&
ccol == 0) || (crow == 3 &&
ccol == 3)) )
errol; }
992 if (p !=
a)
delete [] p;
void beCopyOf(const double *src)
virtual double give_lenght(void) const =0
int length_printed_vector(int precision) const
bool GaussSolve(Dvctr &x, const Dvctr &rhs)
gaussian eliminatio
int length_printed(int precision) const
void round2zero (double zero, double absZero);
void tmsLeftBy(const Dmtrx &src)
double give_zero(double abszero, double relzero) const
int length_printed(int precision) const
double give_dotproduct(const Dvctr &v)
int length_printed_tensor(int precision) const
void print_tensor(FILE *stream, int precision, double absZero, bool zerorest) const
print yourself
void realloc(long newsize)
reallocate up receiver
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
void be_mtrxMmtrx(const Dmtrx &A, const Dmtrx &B)
void beRotatedPoint(const Dmtrx *rot, const PoinT *point)
Receiver will be point 'point' rotated by matrix 'rot'. this = rot . point.
virtual long give_size(void) const
void realloc(long newsize)
reallocate up receiver
#define NUM_DIGITS_IN_PRINTED_EXPONENT
void tmsRightBy(const Dmtrx &src)
Lvctr * assign_array(long *array, long s)
void pprint_tensor_zero(char *stream, int precision)
void pprint_symtensor_zeroL(char *stream, int precision)
double give_copy_r2z(double a, double zero)
double give_sum(void) const
double give_determinant(void) const
void be_transposition(const Dmtrx &src)
void resize_ignore_vals(long r, long c)
print yourself
void sbt(const Dvctr &src)
void be_vectproduct(const Dvctr &v1, const Dvctr &v2)
Structs Elem3D, PoinT and VectoR; classes Array, Array1d, Xscal, Dscal, Xvctr, Lvctr, Dvctr, Xmtrx, Lmtrx and Dmtrx.
Dvctr * resize_ignore_vals(long newsize)
void beCopyOf(const PoinT &src)
long give_sum(void) const
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
void print(char *stream, int precision, double absZero=0.0) const
void be_tnsr(const Dvctr &src)
double give_lenght(void) const
void print(char *stream, int precision, double absZero=0.0) const
void resize_ignore_vals(long r, long c)
double give_lenght(void) const
void add(const Dvctr &src)
void rotate(Dvctr *v) const
#define _errorr3(_1, _2, _3)
Dvctr * assign_array(double *array, long s)
virtual void print(char *stream, int precision, double absZero=0.0) const
void be_mean_of(const Dmtrx *src)
void pprint_tensor(FILE *stream, int precision, const double *a)
int length_printed_tensor(int precision) const
long give_number_of_nonzeros(void) const
void tnsrRotAxisZangle(double a)
rotate coord system around axis z by angle
void tnsrRotWith(const Dmtrx &rot)
this = rot * this * rot^transp
void be_tnsr(const Dmtrx &src)
double * give_ptr2val(long r=0, long c=0)
long give_number_of_zeros(void) const
double * give_ptr2val(long i=0)
return pointer to
void addtms(const Dvctr &src, double tms)
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
long give_ccols(void) const
int length_printed_vector(int precision) const
long give_crows(void) const
void pprint_symtensor(char *stream, int precision, const long *a)