Lemma is an Electromagnetics API
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

utgaussquad.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // ===========================================================================
  2. //
  3. // Filename: utqaussquad.cpp
  4. //
  5. // Description: Test for gaussian quadrature algorithm
  6. //
  7. // Version: 0.0
  8. // Created: 10/05/2010 08:54:26 AM
  9. // Revision: none
  10. // Compiler: Tested with g++
  11. //
  12. // Author: M. Andy Kass (MAK)
  13. //
  14. // Organisation: Colorado School of Mines (CSM)
  15. // Broken Spoke Development, LLC
  16. //
  17. // Email: mkass@numericalgeo.com
  18. //
  19. // This program is free software: you can redistribute it and/or modify
  20. // it under the terms of the GNU General Public License as published by
  21. // the Free Software Foundation, either version 3 of the License, or
  22. // (at your option) any later version.
  23. //
  24. // This program is distributed in the hope that it will be useful,
  25. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. // GNU General Public License for more details.
  28. //
  29. // You should have received a copy of the GNU General Public License
  30. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. //
  32. // ===========================================================================
  33. #include "Lemma"
  34. using namespace Lemma;
  35. using namespace std;
  36. #ifdef LEMMAUSEVTK
  37. #include "matplot.h"
  38. using namespace matplot;
  39. #endif
  40. int main() {
  41. int N = 600;
  42. int upb = 5;
  43. int lowb = -1;
  44. VectorXr func(N);
  45. VectorXr wx(N);
  46. Real integrationres,actres;
  47. gaussianquadrature *lgqw = gaussianquadrature::New();
  48. lgqw->SetFreqs(N,upb,lowb);
  49. lgqw->CalcAW();
  50. wx=lgqw->GetAbscissae();
  51. func=cos(wx.array());
  52. // for (int ii=0;ii<N;++ii) {
  53. // cout << wx(ii) << " " << func(ii) << endl;
  54. // }
  55. lgqw->SetFunc(func);
  56. lgqw->Integrate();
  57. integrationres=lgqw->GetResult();
  58. actres = -sin((Real)upb)+sin((Real)lowb);
  59. cout << "Gaussian Quadrature Result: " << integrationres << endl;
  60. cout << "Actual Result: " << actres << endl;
  61. //Plot things
  62. #ifdef LEMMAUSEVTK
  63. double colour1[3] = {0.0,0.0,1.0};
  64. Plot2D_VTK p1("X", "Y", 800,600);
  65. p1.plot(wx,func,colour1,".-");
  66. p1.show();
  67. #endif
  68. return EXIT_SUCCESS;
  69. }