1.3.1 自分用の泥縄チュートリアル


//
// newtest1.cpp --- 級数の和を求める
// g++ -O3 -I/usr/local/include/profil -o newtest1 newtest1.cpp -lProfil -lBias -llr
// 2020/8/30 15:02:36
// 

#include <iostream>
#include <iomanip>
#include <Interval.h>

int main(void)
{
  int i, n;
  INTERVAL s, s2;
  n = 1000;
  for (i = 1; i<= n; i++) {
    s += 1 / Hull(i);
    s2 += 1 / Hull(i*i);
  }
  cout << "1/1+1/2+...+1/" << n << "=" << s << endl;
  cout << "1/1^2+1/2^2+...+1/" << n << "^2=" << s2 << endl;
  return 0;
}
実行結果
% g++ -O3 -I/usr/local/include/profil -o newtest1 newtest1.cpp -lProfil -lBias -llr
% ./newtest1
1/1+1/2+...+1/1000=7.485470860549[9560,18238]
1/1^2+1/2^2+...+1/1000^2=1.643934566681[4504,6703]


//
// newtest2.cpp --- 無理数の定数を包含する区間を得る
// g++ -O3 -I/usr/local/include/profil -o newtest2 newtest2.cpp -lProfil -lBias -llr
// 2020/8/30 15:03:00
//

#include <iostream>
#include <iomanip>
#include <Interval.h>
#include <Functions.h>

int main(void)
{
  int i, n;
  INTERVAL iRoot2(Pred(Sqrt(2.0)),Succ(Sqrt(2.0)));
  INTERVAL iPi(Pred(Constant::Pi),Succ(Constant::Pi));
  INTERVAL iE = Exp(Hull(1));
  // 1.41421356237309504880168872421
  cout << "√2="  << iRoot2 << endl;
  // 3.14159265358979323846264338328
  cout << "π="  << iPi << endl;
  // 2.71828182845904523536028747135
  cout << "e="  << iE << endl;
  return 0;
}
実行結果
% g++ -O3 -I/usr/local/include/profil -o newtest2 newtest2.cpp -lProfil -lBias -llr
% ./newtest2
√2=1.41421356237309[49,54]
π=3.14159265358979[26,36]
e=2.71828182845904[46,74]

桂田 祐史
2020-09-03