NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
11-numcxx-ref.cxx
Go to the documentation of this file.
1 
7 #include <cstdio>
8 #include <numcxx/numcxx.hxx>
9 
10 // initialize vector x with some data
12 {
13  const int n=X.size();
14  for (int i=0;i<n;i++) X(i)= 1.0/(double)(1+n-i);
15 }
16 
17 // calculate the sum of the elements of x
19 {
20  double sum=0;
21  for (int i=0;i<X.size();i++)sum+=X(i);
22  return sum;
23 }
24 
25 int main()
26 {
27  const int n=12345678;
28  // call constructor
30  initialize(X);
31  double s=sum_elements(X);
32  printf("sum=%e\n",s);
33 }
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58
Main header of the library.
void initialize(numcxx::DArray1 &X)
One dimensional array class.
Definition: tarray1.hxx:31
A::value_type sum(const A &a)
Sum of array or expression.
Definition: util.ixx:81
double sum_elements(numcxx::DArray1 &X)
int main()