HOME   ≫   SOFTWARE   ≫   USER GUIDE AND DOCUMENTATION   ≫   PRELIMINARY EXAMPLE 1


Software

User Guide and Documentation ‐ Preliminary Example 1

Simple matrix addition in C++11 with Yotcopi

[ Download : first.cpp ]
#include <yotcopi.hpp>

int main(int argc, char** argv)
{
  using namespace yotcopi;
  using namespace yotcopi::shortkeys;

  auto A = m({{1,2},{3,4}});
  auto B = m({{5,6},{7,8}});

  std::cout << A + B << "\n";

  return 0;
}

Compiling the Yotcopi code by
ymake first
and running the program
./first
the following output will be shown on the console.
              6              8
             10             12


In the following, the code will be explained line-by-line.

First, the Yotcopi header file has to be included:
#include <yotcopi.hpp>
Second, it is highly recommended to use the following namespaces for convenience:
using namespace yotcopi;
using namespace yotcopi::shortkeys;
Third, we declare 2 dense, real matrices A and B, of Yotcopi-defined type m:
auto A = m({{1,2},{3,4}});
auto B = m({{5,6},{7,8}});
Last, the result of matrix addition, ie. A + B, is outputed to the stream, in this case the terminal console:
std::cout << A + B << "\n";

More information can be found in the user guide. See more ≫
[Top]