Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //File Error.cpp
- #include<iostream>
- #include<math.h>
- #include"Error.h"
- #include"Function.h"
- using namespace std;
- void Error::setValues( double *v, int length, double mult ) {
- this->v = v;
- this->length = length;
- this->mult = mult;
- length_2 = length * 0.5;
- cout << "test" << endl;
- }
- void Error::setCoefficients( double *x0, double *y0, double *a, double *c, int size ) {
- this->x0 = x0;
- this->y0 = y0;
- this->a = a;
- this->c = c;
- this->size = size;
- }
- void Error::calcError() {
- error = 0;
- double dv;
- double vtmp;
- for ( int i = 0; i < length; i++ )
- for ( int j = 0; j < length; j++ ) {
- vtmp = 0.0;
- for ( int k = 0; k < size; k++ )
- vtmp += Function::value( ( i - length_2 ) * mult, ( j - length_2 ) * mult, x0[k], y0[k], a[k], c[k] );
- dv = v[ i * length + j ] - vtmp;
- error += dv * dv;
- }
- }
- double Error::getError() {
- return sqrt( error );
- }
- //File Error.h
- class Error {
- private:
- double *v;
- double *x0;
- double *y0;
- double *a;
- double *c;
- int length; // grid length
- double length_2;
- double mult;
- int size; // number of gausses to add
- double error;
- public:
- void setValues( double *v, int length, double mult );
- void setCoefficients( double *x0, double *y0, double *a, double *c, int size );
- void calcError();
- double getError();
- };
- //Function code
- double Function::value( double x, double y, double x0, double y0, double a, double c ) {
- return a * exp( - ( ( x - x0 )*( x - x0 ) + ( y - y0 )*( y - y0 ) ) * c );
- }
Add Comment
Please, Sign In to add comment