Guest User

Untitled

a guest
Feb 14th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. //File Error.cpp
  2.  
  3. #include<iostream>
  4. #include<math.h>
  5. #include"Error.h"
  6. #include"Function.h"
  7.  
  8.  
  9. using namespace std;
  10.  
  11. void Error::setValues( double *v, int length, double mult ) {
  12.    this->v = v;
  13.    this->length = length;
  14.    this->mult = mult;
  15.    length_2 = length * 0.5;
  16.    cout << "test" << endl;
  17. }
  18.  
  19. void Error::setCoefficients( double *x0, double *y0, double *a, double *c, int size ) {
  20.    this->x0 = x0;
  21.    this->y0 = y0;
  22.    this->a = a;
  23.    this->c = c;
  24.    this->size = size;
  25. }
  26.  
  27. void Error::calcError() {
  28.    error = 0;
  29.    double dv;
  30.    double vtmp;
  31.    for ( int i = 0; i < length; i++ )
  32.     for ( int j = 0; j < length; j++ ) {
  33.        vtmp = 0.0;
  34.        for ( int k = 0; k < size; k++ )
  35.          vtmp += Function::value( ( i - length_2 ) * mult, ( j - length_2 ) * mult, x0[k], y0[k], a[k], c[k] );
  36.        dv = v[ i * length + j ] - vtmp;
  37.        error += dv * dv;
  38.     }
  39. }
  40.  
  41. double Error::getError() {
  42.    return sqrt( error );
  43. }
  44.  
  45.  
  46. //File Error.h
  47.  
  48. class Error {
  49.         private:
  50.            double *v;
  51.        double *x0;
  52.        double *y0;
  53.        double *a;
  54.            double *c;
  55.            int length;  // grid length
  56.            double length_2;
  57.            double mult;
  58.            int size;  // number of gausses to add
  59.            double error;
  60.     public:
  61.        void setValues( double *v, int length, double mult );
  62.            void setCoefficients( double *x0, double *y0, double *a, double *c, int size );
  63.        void calcError();
  64.        double getError();
  65. };
  66.  
  67.  
  68. //Function code
  69. double Function::value( double x, double y, double x0, double y0, double a, double c ) {
  70.    return a * exp( - ( ( x - x0 )*( x - x0 ) + ( y - y0 )*( y - y0 ) ) * c );
  71. }
Add Comment
Please, Sign In to add comment