43 void init_xy(
float stepsize,
int frequency,
46 void init_x(
int vsize,
float stepsize,
int frequency,
80 float stepsize,
int frequency);
83 float stepsize,
int frequency);
86 float stepsize,
int frequency);
89 float stepsize,
int frequency);
92 float stepsize,
int frequency);
95 float stepsize,
int frequency);
105 int main(
int argc,
char *argv[])
108 { cerr << argv[0] <<
" requires one parameter" << endl; exit (1); }
110 cout <<
"Uebergabewert von argv : " << argv[1] << endl;
112 int frequency = (int)strtol(argv[1], NULL, 10);
113 cout <<
"Wert von frequency : " << frequency << endl;
120 test_xy(181, 361, 1.0, frequency);
138 void init_x(
int vsize,
float stepsize,
int frequency,
141 cout <<
"----------------init_x---------------\n";
146 for (
int i = 0; i < Integrand.
nelem(); i++)
147 Integrand[i] = (
float)i * stepsize;
150 for (
int i = 0; i < Theta.
nelem(); i++)
151 Theta[i] = (
float)i * stepsize;
153 cout <<
"function Y = X" << endl
154 <<
"vsize = " << vsize << endl
155 <<
"stepsize = " << stepsize << endl
156 <<
"frequency = " << frequency << endl
157 <<
"Integrand: von " << Integrand[0] <<
" bis "
158 << Integrand[Integrand.
nelem() - 1] << endl
159 <<
"Theta: von " << Theta[0] <<
" bis "
160 << Theta[Theta.
nelem() - 1] << endl;
172 cout <<
">>>>>-----------init_xy---------------\n";
177 for (
Index i = 0; i < n_za; i++)
178 for (
Index j = 0; j < n_aa; j++)
182 for (
Index i = 0; i < n_za; i++)
183 za_grid[i] = (
float)i * stepsize;
186 for (
Index i = 0; i < n_aa; i++)
187 aa_grid[i] = (
float)i * stepsize;
189 cout <<
"function x^2 + y^2 + z^2 = 1" << endl
190 <<
"n_za = " << n_za << endl
191 <<
"n_aa = " << n_aa << endl
192 <<
"stepsize = " << stepsize << endl
193 <<
"frequency = " << frequency << endl
194 <<
"Integrand(*,0): von " << Integrand(0,0) <<
" bis "
195 << Integrand(n_za - 1, 0) << endl
196 <<
"Integrand(0,*): von " << Integrand(0,0) <<
" bis "
197 << Integrand(0, n_aa - 1) << endl
198 <<
"za_grid (Theta): von " << za_grid[0] <<
" bis "
199 << za_grid[za_grid.
nelem() - 1] << endl
200 <<
"aa_grid (Phi) : von " << aa_grid[0] <<
" bis "
201 << aa_grid[aa_grid.
nelem() - 1] << endl;
202 cout <<
"---------------init_xy---------------<<<<<\n";
226 assert (
is_size(Integrand, n, m));
228 for (
Index i = 0; i < n ; ++i)
232 for (
Index j = 0; j < m - 1; ++j)
234 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
235 (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] *
DEG2RAD);
239 for (
Index i = 0; i < n - 1; ++i)
241 res += 0.5 *
DEG2RAD * (res1[i] + res1[i + 1]) *
242 (za_grid[i + 1] - za_grid[i]);
268 assert (
is_size(Integrand, n, m));
270 for (
Index i = 0; i < n ; ++i)
274 for (
Index j = 0; j < m - 1; ++j)
276 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
277 (aa_grid[j + 1] - aa_grid[j]) * sin(za_grid[i] *
DEG2RAD);
281 for (
Index i = 0; i < n - 1; ++i)
283 res += 0.5 *
DEG2RAD * (res1[i] + res1[i + 1]) *
284 (za_grid[i + 1] - za_grid[i]);
312 assert (
is_size(Integrand, n, m));
314 for (
Index i = 0; i < n ; ++i)
318 for (
Index j = 0; j < m - 1; ++j)
320 res1[i] += 0.5 *
DEG2RAD * (Integrand(i, j) + Integrand(i, j + 1)) *
321 stepsize * sin(za_grid[i] *
DEG2RAD);
325 for (
Index i = 0; i < n - 1; ++i)
327 res += 0.5 *
DEG2RAD * (res1[i] + res1[i + 1]) * stepsize;
355 assert (
is_size(Integrand, n, m));
357 for (
Index i = 0; i < n ; ++i)
361 res1[i] += Integrand(i, 0);
362 for (
Index j = 1; j < m - 1; j++)
364 res1[i] += Integrand(i, j) * 2;
366 res1[i] += Integrand(i, m-1);
371 for (
Index i = 1; i < n - 1; i++)
376 res *= 0.5 *
DEG2RAD * stepsize;
405 assert (
is_size(Integrand, n, m));
409 for (
Index i = 0; i < n ; ++i)
411 temp = Integrand(i, 0);
412 for (
Index j = 1; j < m - 1; j++)
414 temp += Integrand(i, j) * 2;
416 temp += Integrand(i, m-1);
422 for (
Index i = 1; i < n - 1; i++)
427 res *= 0.5 *
DEG2RAD * stepsize;
443 assert (
is_size(Integrand, n));
446 for (
Index i = 0; i < n - 1; ++i)
450 + Integrand[i + 1] * sin(za_grid[i + 1] *
DEG2RAD))
451 * (za_grid[i + 1] - za_grid[i]);
468 assert (
is_size(Integrand, n));
472 res += (Integrand[0] * sin(za_grid[0] *
DEG2RAD));
473 for (
Index i = 1; i < n - 1 ; ++i)
475 res += (Integrand[i] * sin(za_grid[i] *
DEG2RAD) * 2);
478 res += ((Integrand[n-1] * sin(za_grid[n-1] *
DEG2RAD)));
501 float stepsize,
int frequency)
503 cout <<
">>>>>-----------test_xy---------------\n";
504 Matrix Integrand(z_size, a_size);
508 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
512 struct timeval start;
514 gettimeofday(&start, NULL);
518 for (
int i = 0; i < frequency; i++)
521 gettimeofday(&ende, NULL);
523 double error = result/(4*
PI) - 1;
525 double diffs = (double)(ende.tv_sec - start.tv_sec)
526 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
528 cout <<
"stepsize is : " << stepsize << endl
529 <<
"z_size : " << z_size << endl
530 <<
"a_size : " << a_size << endl
531 <<
"1 is : " << result/(4*
PI) << endl
532 <<
"The result is : " << result << endl
533 <<
"The error is : " << error*100 <<
" %\n"
534 <<
"Number of loops: " << frequency << endl
535 <<
"elapsed time : " << diffs <<
"s" << endl
536 <<
"----------------test_xy----------<<<<<\n";
555 float stepsize,
int frequency)
557 cout <<
">>>>>-----------test_xy_opt---------------\n";
558 Matrix Integrand(z_size, a_size);
562 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
566 struct timeval start;
568 gettimeofday(&start, NULL);
572 for (
int i = 0; i < frequency; i++)
575 gettimeofday(&ende, NULL);
577 double error = result/(4*
PI) - 1;
579 double diffs = (double)(ende.tv_sec - start.tv_sec)
580 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
582 cout <<
"stepsize is : " << stepsize << endl
583 <<
"z_size : " << z_size << endl
584 <<
"a_size : " << a_size << endl
585 <<
"1 is : " << result/(4*
PI) << endl
586 <<
"The result is : " << result << endl
587 <<
"The error is : " << error*100 <<
" %\n"
588 <<
"Number of loops: " << frequency << endl
589 <<
"elapsed time : " << diffs <<
"s" << endl
590 <<
"----------------test_xy_opt----------<<<<<\n";
609 float stepsize,
int frequency)
611 cout <<
">>>>>-----------test_xy_fixedstep---------------\n";
612 Matrix Integrand(z_size, a_size);
616 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
620 struct timeval start;
622 gettimeofday(&start, NULL);
626 for (
int i = 0; i < frequency; i++)
629 gettimeofday(&ende, NULL);
631 double error = result/(4*
PI) - 1;
633 double diffs = (double)(ende.tv_sec - start.tv_sec)
634 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
636 cout << diffs << endl;
637 cout <<
"stepsize is : " << stepsize << endl
638 <<
"z_size : " << z_size << endl
639 <<
"a_size : " << a_size << endl
640 <<
"1 is : " << result/(4*
PI) << endl
641 <<
"The result is : " << result << endl
642 <<
"The error is : " << error*100 <<
" %\n"
643 <<
"Number of loops: " << frequency << endl
644 <<
"elapsed time : " << diffs <<
"s" << endl
645 <<
"----------------test_xy_fixedstep----------<<<<<\n";
664 float stepsize,
int frequency)
666 cout <<
">>>>>-----------test_xy_fixedstep_opt---------------\n";
667 Matrix Integrand(z_size, a_size);
671 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
675 struct timeval start;
677 gettimeofday(&start, NULL);
681 for (
int i = 0; i < frequency; i++)
684 gettimeofday(&ende, NULL);
686 double error = result/(4*
PI) - 1;
688 double diffs = (double)(ende.tv_sec - start.tv_sec)
689 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
691 cout << diffs << endl;
692 cout <<
"stepsize is : " << stepsize << endl
693 <<
"z_size : " << z_size << endl
694 <<
"a_size : " << a_size << endl
695 <<
"1 is : " << result/(4*
PI) << endl
696 <<
"The result is : " << result << endl
697 <<
"The error is : " << error*100 <<
" %\n"
698 <<
"Number of loops: " << frequency << endl
699 <<
"elapsed time : " << diffs <<
"s" << endl
700 <<
"----------------test_xy_fixedstep_opt----------<<<<<\n";
719 float stepsize,
int frequency)
721 cout <<
">>>>>-----------test_xy_fixedstep_opt2---------------\n";
722 Matrix Integrand(z_size, a_size);
726 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
730 struct timeval start;
732 gettimeofday(&start, NULL);
736 for (
int i = 0; i < frequency; i++)
739 gettimeofday(&ende, NULL);
741 double error = result/(4*
PI) - 1;
743 double diffs = (double)(ende.tv_sec - start.tv_sec)
744 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
746 cout << diffs << endl;
747 cout <<
"stepsize is : " << stepsize << endl
748 <<
"z_size : " << z_size << endl
749 <<
"a_size : " << a_size << endl
750 <<
"1 is : " << result/(4*
PI) << endl
751 <<
"The result is : " << result << endl
752 <<
"The error is : " << error*100 <<
" %\n"
753 <<
"Number of loops: " << frequency << endl
754 <<
"elapsed time : " << diffs <<
"s" << endl
755 <<
"----------------test_xy_fixedstep_opt2----------<<<<<\n";
775 float stepsize,
int frequency)
777 cout <<
">>>>>-----------test_AngIntegrate_trapezoid_opti---------------\n";
778 Matrix Integrand(z_size, a_size);
784 init_xy(stepsize, frequency, Integrand, za_grid, aa_grid);
786 grid_stepsize[0] = za_grid[1] - za_grid[0];
787 grid_stepsize[1] = aa_grid[1] - aa_grid[0];
797 struct timeval start;
799 gettimeofday(&start, NULL);
803 for (
int i = 0; i < frequency; i++)
806 gettimeofday(&ende, NULL);
808 double error = result/(4*
PI) - 1;
810 double diffs = (double)(ende.tv_sec - start.tv_sec)
811 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
813 cout << diffs << endl;
814 cout <<
"stepsize is : " << stepsize << endl
815 <<
"z_size : " << z_size << endl
816 <<
"a_size : " << a_size << endl
817 <<
"1 is : " << result/(4*
PI) << endl
818 <<
"The result is : " << result << endl
819 <<
"The error is : " << error*100 <<
" %\n"
820 <<
"Number of loops: " << frequency << endl
821 <<
"elapsed time : " << diffs <<
"s" << endl
822 <<
"----------------test_AngIntegrate_trapezoid_opti----------<<<<<\n";
844 cout <<
">>>>>-----------test_x---------------\n";
848 init_x(vsize, stepsize, frequency, Integrand, Theta);
852 struct timeval start;
854 gettimeofday(&start, NULL);
855 cout <<
"Sekunden : " << start.tv_sec << endl
856 <<
"Milisekunden: " << start.tv_usec << endl;
858 for (
int i = 0; i < frequency; i++)
861 gettimeofday(&ende, NULL);
864 result = result / (2*180);
866 double error = result/
PI - 1;
870 double diffs = (double)(ende.tv_sec - start.tv_sec)
871 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
873 cout << diffs << endl;
874 cout <<
"stepsize is : " << stepsize << endl
875 <<
"number of steps: " << vsize << endl
876 <<
"1 is : " <<
PI/
PI << endl
877 <<
"The result is : " << result/
PI << endl
878 <<
"The error is : " << error*100 <<
"%\n"
879 <<
"Number of loops: " << frequency << endl
880 <<
"elapsed time : " << diffs <<
"s" << endl
881 <<
"---------------test_x-----------<<<<<\n";
899 cout <<
">>>>>-----------test_x_fixedstep---------------\n";
905 stepsize = 180.0 / (vsize - 1);
906 cout <<
"Neue berechnete Stepsize: " << stepsize << endl;
908 for (
int i = 0; i < Integrand.
nelem(); i++)
909 Integrand[i] = i * stepsize;
912 for (
int i = 0; i < Theta.
nelem(); i++)
913 Theta[i] = i * stepsize;
916 cout <<
"Integrand: von " << Integrand[0] <<
" bis "
917 << Integrand[Integrand.
nelem() - 1] << endl
918 <<
"Theta: von " << Theta[0] <<
" bis "
919 << Theta[Theta.
nelem() - 1] << endl;
923 struct timeval start;
925 gettimeofday(&start, NULL);
926 cout <<
"Sekunden : " << start.tv_sec << endl
927 <<
"Milisekunden: " << start.tv_usec << endl;
929 for (
int i = 0; i < frequency; i++)
932 gettimeofday(&ende, NULL);
935 result = result / (2*180);
937 double error = result/
PI - 1;
941 double diffs = (double)(ende.tv_sec - start.tv_sec)
942 + (double)(ende.tv_usec - start.tv_usec)/1000000.0;
944 cout << diffs << endl;
945 cout <<
"stepsize is : " << stepsize << endl
946 <<
"number of steps: " << vsize << endl
947 <<
"1 is : " <<
PI/
PI << endl
948 <<
"The result is : " << result/
PI << endl
949 <<
"The error is : " << error*100 <<
"%\n"
950 <<
"Number of loops: " << frequency << endl
951 <<
"elapsed time : " << diffs <<
"s" << endl
952 <<
"---------------test_x_fixedstep----------<<<<<\n";