コード例 #1
0
void Variog_plot::refresh() {
  const int discretization = 1500;

  GsTLPoint p1(0,0,0);

  //Code to decide what the increment should be in plotting the continuous model
  double incr = max_x_ / double(discretization);
  if( incr == 0 ) incr = 1;
    

  double x[discretization], y[discretization];
    
  for ( int i = 0 ; i < discretization ; i++ ) {
  	GsTLPoint p2( (p1.x()+i*incr*angle_.x()), 
	        	      (p1.y()+i*incr*angle_.y()),
		              (p1.z()+i*incr*angle_.z()) );

    GsTLVector<double> v = (p2-p1);

    x[i] = euclidean_norm( v );
    y[i] = ((*model1_)( p1, p2 ));

  }

  curve2_->setData( x, y, discretization);
  this->replot();    
}
コード例 #2
0
ファイル: lin_alg.c プロジェクト: edlafem1/math627
double frobenius_check(double *known, double *computed, int m, int n, int id, int np) {
	int l_num_elements = m*n / np;

    if (computed == NULL) {
        return euclidean_norm(known, m*n, id, np);
    }

	double *difference = allocate_double_vector(l_num_elements);

	for (int i = 0; i < l_num_elements; i++) {
		difference[i] = computed[i] - known[i];
	}
    double e_norm = euclidean_norm(difference, m*n, id, np);
    free(difference);

    return e_norm;
}
コード例 #3
0
void
test_euclidean_norm(void) {
    /* double
     * euclidean_norm(
     *     const double *x,
     *     int n
     * ); */
    int i;

    for (i = 0; i < n; ++i) {
        x[i] = 0.;
        y[i] = 0.;
    }
    x[5] = 1.;
    y[1] = -2.;
    CU_ASSERT_EQUAL(1., euclidean_norm(x, n));
    CU_ASSERT_EQUAL(2., euclidean_norm(y, n));
}
コード例 #4
0
ファイル: direction_3d.cpp プロジェクト: ahinoamp/Research
void Direction_3d::set_direction( const GsTLVector<float>& v ) {
  dir_ = v;

  // normalize dir_
  float norm = euclidean_norm( dir_ );
  dir_.x() = dir_.x() / norm;
  dir_.y() = dir_.y() / norm;
  dir_.z() = dir_.z() / norm;
}
コード例 #5
0
/* >>> start tutorial code >>> */
int main( ){

    USING_NAMESPACE_ACADO

    int i;

    // DEFINE VALRIABLES:
    // ---------------------------
    Matrix                 A(3,3);
    Vector                 b(3);
    DifferentialState      x(3);
    DifferentialState      y;
    Function               f[7];

    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    A.setZero() ;
    A(0,0) = 1.0;  A(1,1) = 2.0;  A(2,2) = 3.0;
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE TEST FUNCTIONS:
    // -----------------------
    f[0] << A*x + b;
    f[1] << y + euclidean_norm(A*x + b);
    f[2] << y*y;
    f[3] << square(y);
    f[4] << 5.0*log_sum_exp( x );
//    f[5] << entropy( y );
    f[6] << -sum_square( x );


    for( i = 0; i < 7; i++ ){
        if( f[i].isConvex() == BT_TRUE )
            printf("f[%d] is convex. \n", i );
        else{
            if( f[i].isConcave() == BT_TRUE )
                  printf("f[%d] is concave. \n", i );
            else
                  printf("f[%d] is neither convex nor concave. \n", i );
        }
    }
    return 0;
}
コード例 #6
0
ファイル: gram_schmidt.c プロジェクト: edlafem1/math627
/**
Normalizes a vector of length m with the Euclidean norm.
*/
void normalize(double *v, int m) {
    double norm = euclidean_norm(v, m);
    for (int i = 0; i < m; i++) {
        v[i] /= norm;
    }
}
コード例 #7
0
void householders(
    orthotope<T> const& A
    )
{
    BOOST_ASSERT(2 == A.order());
    BOOST_ASSERT(A.hypercube());

    std::size_t const n = A.extent(0);

    orthotope<T> R = A.copy();
    orthotope<T> Q({n, n});

    for (std::size_t l = 0; l < n; ++l)
        Q(l, l) = 1.0;

    for (std::size_t l = 0; l < (n - 1); ++l)
    {
        T const sigma = compute_sigma(R, n, l);
        boost::int16_t const sign = compute_sign(R(l, l));

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            std::cout << (std::string(80, '#') + "\n")
                      << "ROUND " << l << "\n\n";

            print(sigma, "sigma");
            print(sign, "sign");
        #endif

        orthotope<T> w({n});

        w(l) = R(l, l) + sign * sigma;
 
        for (std::size_t i = (l + 1); i < w.extent(0); ++i)
            w(i) = R(i, l);

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(w, "u");
        #endif

        T const w_norm = euclidean_norm(w);

        for (std::size_t i = l; i < n; ++i)
            w(i) /= w_norm;

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(w, "v");
        #endif

        orthotope<T> H = compute_H(w);

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(H, "H");
        #endif

        R = matrix_multiply(H, R);

        Q = matrix_multiply(Q, H);

        for (std::size_t i = l + 1; i < n; ++i)
            R(i, l) = 0;
    }

    #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
        std::cout << std::string(80, '#') << "\n";
    #endif

    print(A, "A");
    print(Q, "Q");
    print(R, "R");

    #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
        check_QR(A, Q, R);
    #endif
}