50 int vsize,
float stepsize,
int frequency,
Vector& Integrand,
Vector& Theta);
82 Numeric test_xy(
int z_size,
int a_size,
float stepsize,
int frequency);
110 int main(
int argc,
char* argv[]) {
112 cerr << argv[0] <<
" requires one parameter" << endl;
116 cout <<
"Uebergabewert von argv : " << argv[1] << endl;
118 int frequency = (int)strtol(argv[1], NULL, 10);
119 cout <<
"Wert von frequency : " << frequency << endl;
126 test_xy(181, 361, 1.0, frequency);
148 cout <<
"----------------init_x---------------\n";
153 for (
int i = 0; i < Integrand.
nelem(); i++)
154 Integrand[i] = (
float)i * stepsize;
157 for (
int i = 0; i < Theta.
nelem(); i++) Theta[i] = (
float)i * stepsize;
159 cout <<
"function Y = X" << endl
160 <<
"vsize = " << vsize << endl
161 <<
"stepsize = " << stepsize << endl
162 <<
"frequency = " << frequency << endl
163 <<
"Integrand: von " << Integrand[0] <<
" bis "
164 << Integrand[Integrand.
nelem() - 1] << endl
165 <<
"Theta: von " << Theta[0] <<
" bis " << Theta[Theta.
nelem() - 1]
179 cout <<
">>>>>-----------init_xy---------------\n";
184 for (
Index i = 0; i < n_za; i++)
185 for (
Index j = 0; j < n_aa; j++) Integrand(i, j) = 1;
188 for (
Index i = 0; i < n_za; i++)
za_grid[i] = (
float)i * stepsize;
191 for (
Index i = 0; i < n_aa; i++)
aa_grid[i] = (
float)i * stepsize;
193 cout <<
"function x^2 + y^2 + z^2 = 1" << endl
194 <<
"n_za = " << n_za << endl
195 <<
"n_aa = " << n_aa << endl
196 <<
"stepsize = " << stepsize << endl
197 <<
"frequency = " << frequency << endl
198 <<
"Integrand(*,0): von " << Integrand(0, 0) <<
" bis "
199 << Integrand(n_za - 1, 0) << endl
200 <<
"Integrand(0,*): von " << Integrand(0, 0) <<
" bis "
201 << Integrand(0, n_aa - 1) << endl
202 <<
"za_grid (Theta): von " <<
za_grid[0] <<
" bis "
204 <<
"aa_grid (Phi) : von " <<
aa_grid[0] <<
" bis "
206 cout <<
"---------------init_xy---------------<<<<<\n";
227 assert(
is_size(Integrand, n, m));
229 for (
Index i = 0; i < n; ++i) {
232 for (
Index j = 0; j < m - 1; ++j) {
233 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
238 for (
Index i = 0; i < n - 1; ++i) {
264 assert(
is_size(Integrand, n, m));
266 for (
Index i = 0; i < n; ++i) {
269 for (
Index j = 0; j < m - 1; ++j) {
270 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
275 for (
Index i = 0; i < n - 1; ++i) {
304 assert(
is_size(Integrand, n, m));
306 for (
Index i = 0; i < n; ++i) {
309 for (
Index j = 0; j < m - 1; ++j) {
310 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
315 for (
Index i = 0; i < n - 1; ++i) {
316 res += 0.5 *
DEG2RAD * (res1[i] + res1[i + 1]) * stepsize;
343 assert(
is_size(Integrand, n, m));
345 for (
Index i = 0; i < n; ++i) {
348 res1[i] += Integrand(i, 0);
349 for (
Index j = 1; j < m - 1; j++) {
350 res1[i] += Integrand(i, j) * 2;
352 res1[i] += Integrand(i, m - 1);
357 for (
Index i = 1; i < n - 1; i++) {
361 res *= 0.5 *
DEG2RAD * stepsize;
388 assert(
is_size(Integrand, n, m));
392 for (
Index i = 0; i < n; ++i) {
393 temp = Integrand(i, 0);
394 for (
Index j = 1; j < m - 1; j++) {
395 temp += Integrand(i, j) * 2;
397 temp += Integrand(i, m - 1);
403 for (
Index i = 1; i < n - 1; i++) {
407 res *= 0.5 *
DEG2RAD * stepsize;
423 for (
Index i = 0; i < n - 1; ++i) {
448 for (
Index i = 1; i < n - 1; ++i) {
474 cout <<
">>>>>-----------test_xy---------------\n";
475 Matrix Integrand(z_size, a_size);
483 struct timeval
start;
485 gettimeofday(&
start, NULL);
489 for (
int i = 0; i < frequency; i++)
492 gettimeofday(&ende, NULL);
494 double error = result / (4 *
PI) - 1;
496 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
497 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
499 cout <<
"stepsize is : " << stepsize << endl
500 <<
"z_size : " << z_size << endl
501 <<
"a_size : " << a_size << endl
502 <<
"1 is : " << result / (4 *
PI) << endl
503 <<
"The result is : " << result << endl
504 <<
"The error is : " << error * 100 <<
" %\n"
505 <<
"Number of loops: " << frequency << endl
506 <<
"elapsed time : " << diffs <<
"s" << endl
507 <<
"----------------test_xy----------<<<<<\n";
525 cout <<
">>>>>-----------test_xy_opt---------------\n";
526 Matrix Integrand(z_size, a_size);
534 struct timeval
start;
536 gettimeofday(&
start, NULL);
540 for (
int i = 0; i < frequency; i++)
543 gettimeofday(&ende, NULL);
545 double error = result / (4 *
PI) - 1;
547 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
548 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
550 cout <<
"stepsize is : " << stepsize << endl
551 <<
"z_size : " << z_size << endl
552 <<
"a_size : " << a_size << endl
553 <<
"1 is : " << result / (4 *
PI) << endl
554 <<
"The result is : " << result << endl
555 <<
"The error is : " << error * 100 <<
" %\n"
556 <<
"Number of loops: " << frequency << endl
557 <<
"elapsed time : " << diffs <<
"s" << endl
558 <<
"----------------test_xy_opt----------<<<<<\n";
579 cout <<
">>>>>-----------test_xy_fixedstep---------------\n";
580 Matrix Integrand(z_size, a_size);
588 struct timeval
start;
590 gettimeofday(&
start, NULL);
594 for (
int i = 0; i < frequency; i++)
598 gettimeofday(&ende, NULL);
600 double error = result / (4 *
PI) - 1;
602 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
603 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
605 cout << diffs << endl;
606 cout <<
"stepsize is : " << stepsize << endl
607 <<
"z_size : " << z_size << endl
608 <<
"a_size : " << a_size << endl
609 <<
"1 is : " << result / (4 *
PI) << endl
610 <<
"The result is : " << result << endl
611 <<
"The error is : " << error * 100 <<
" %\n"
612 <<
"Number of loops: " << frequency << endl
613 <<
"elapsed time : " << diffs <<
"s" << endl
614 <<
"----------------test_xy_fixedstep----------<<<<<\n";
635 cout <<
">>>>>-----------test_xy_fixedstep_opt---------------\n";
636 Matrix Integrand(z_size, a_size);
644 struct timeval
start;
646 gettimeofday(&
start, NULL);
650 for (
int i = 0; i < frequency; i++)
654 gettimeofday(&ende, NULL);
656 double error = result / (4 *
PI) - 1;
658 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
659 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
661 cout << diffs << endl;
662 cout <<
"stepsize is : " << stepsize << endl
663 <<
"z_size : " << z_size << endl
664 <<
"a_size : " << a_size << endl
665 <<
"1 is : " << result / (4 *
PI) << endl
666 <<
"The result is : " << result << endl
667 <<
"The error is : " << error * 100 <<
" %\n"
668 <<
"Number of loops: " << frequency << endl
669 <<
"elapsed time : " << diffs <<
"s" << endl
670 <<
"----------------test_xy_fixedstep_opt----------<<<<<\n";
691 cout <<
">>>>>-----------test_xy_fixedstep_opt2---------------\n";
692 Matrix Integrand(z_size, a_size);
700 struct timeval
start;
702 gettimeofday(&
start, NULL);
706 for (
int i = 0; i < frequency; i++)
710 gettimeofday(&ende, NULL);
712 double error = result / (4 *
PI) - 1;
714 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
715 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
717 cout << diffs << endl;
718 cout <<
"stepsize is : " << stepsize << endl
719 <<
"z_size : " << z_size << endl
720 <<
"a_size : " << a_size << endl
721 <<
"1 is : " << result / (4 *
PI) << endl
722 <<
"The result is : " << result << endl
723 <<
"The error is : " << error * 100 <<
" %\n"
724 <<
"Number of loops: " << frequency << endl
725 <<
"elapsed time : " << diffs <<
"s" << endl
726 <<
"----------------test_xy_fixedstep_opt2----------<<<<<\n";
749 cout <<
">>>>>-----------test_AngIntegrate_trapezoid_opti---------------\n";
750 Matrix Integrand(z_size, a_size);
769 struct timeval
start;
771 gettimeofday(&
start, NULL);
775 for (
int i = 0; i < frequency; i++)
779 gettimeofday(&ende, NULL);
781 double error = result / (4 *
PI) - 1;
783 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
784 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
786 cout << diffs << endl;
787 cout <<
"stepsize is : " << stepsize << endl
788 <<
"z_size : " << z_size << endl
789 <<
"a_size : " << a_size << endl
790 <<
"1 is : " << result / (4 *
PI) << endl
791 <<
"The result is : " << result << endl
792 <<
"The error is : " << error * 100 <<
" %\n"
793 <<
"Number of loops: " << frequency << endl
794 <<
"elapsed time : " << diffs <<
"s" << endl
795 <<
"----------------test_AngIntegrate_trapezoid_opti----------<<<<<\n";
812 cout <<
">>>>>-----------test_x---------------\n";
816 init_x(vsize, stepsize, frequency, Integrand, Theta);
820 struct timeval
start;
822 gettimeofday(&
start, NULL);
823 cout <<
"Sekunden : " <<
start.tv_sec << endl
824 <<
"Milisekunden: " <<
start.tv_usec << endl;
826 for (
int i = 0; i < frequency; i++)
829 gettimeofday(&ende, NULL);
832 result = result / (2 * 180);
834 double error = result /
PI - 1;
836 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
837 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
839 cout << diffs << endl;
840 cout <<
"stepsize is : " << stepsize << endl
841 <<
"number of steps: " << vsize << endl
842 <<
"1 is : " <<
PI /
PI << endl
843 <<
"The result is : " << result /
PI << endl
844 <<
"The error is : " << error * 100 <<
"%\n"
845 <<
"Number of loops: " << frequency << endl
846 <<
"elapsed time : " << diffs <<
"s" << endl
847 <<
"---------------test_x-----------<<<<<\n";
862 cout <<
">>>>>-----------test_x_fixedstep---------------\n";
871 cout <<
"Neue berechnete Stepsize: " << stepsize << endl;
873 for (
int i = 0; i < Integrand.
nelem(); i++) Integrand[i] = i * stepsize;
876 for (
int i = 0; i < Theta.
nelem(); i++) Theta[i] = i * stepsize;
878 cout <<
"Integrand: von " << Integrand[0] <<
" bis "
879 << Integrand[Integrand.
nelem() - 1] << endl
880 <<
"Theta: von " << Theta[0] <<
" bis " << Theta[Theta.
nelem() - 1]
885 struct timeval
start;
887 gettimeofday(&
start, NULL);
888 cout <<
"Sekunden : " <<
start.tv_sec << endl
889 <<
"Milisekunden: " <<
start.tv_usec << endl;
891 for (
int i = 0; i < frequency; i++)
894 gettimeofday(&ende, NULL);
897 result = result / (2 * 180);
899 double error = result /
PI - 1;
901 double diffs = (double)(ende.tv_sec -
start.tv_sec) +
902 (double)(ende.tv_usec -
start.tv_usec) / 1000000.0;
904 cout << diffs << endl;
905 cout <<
"stepsize is : " << stepsize << endl
906 <<
"number of steps: " << vsize << endl
907 <<
"1 is : " <<
PI /
PI << endl
908 <<
"The result is : " << result /
PI << endl
909 <<
"The error is : " << error * 100 <<
"%\n"
910 <<
"Number of loops: " << frequency << endl
911 <<
"elapsed time : " << diffs <<
"s" << endl
912 <<
"---------------test_x_fixedstep----------<<<<<\n";