template <class T> class complex;
#include <complex> using namespace std; complex<double> 変数名(const double& re = 0.0, const double& im = 0.0); complex<float> 変数名(const float& re = 0.0f, const float& im = 0.0f); complex<long double> 変数名(const long double& re = 0.0L, const long double& im = 0.0L); complex<double> x; // (0, 0), <double> を省略できない(以下は可能) complex<double> x(2.0); // (2, 0) complex<double> x(2.0, 1.0); // (2, 1) complex<double> x(y); // y と同じ複素数 complex<double> x = 1.0i; // (0, 1),float : 1.0if(C++14), long double : 1.0il(C++14) complex<double> x = 2.0; // (2, 0) complex<double> x = {2.0, 1.0}; // (2, 1) complex<double> x {2.0, 1.0}; // (2, 1)
= + - * / == != <<(出力) >>(入力)
#include <iostream> #include <complex> #include <cmath> using namespace std; int main() { // メンバー関数等 complex<double> c1(1.0, 1.0); cout << "複素数 c1 : " << c1 << endl; cout << " real(メンバー関数) " << c1.real() << " real(関数) " << real(c1) << endl; c1.real(2.0); cout << " メンバー関数で実部を変更 c1 : " << c1 << endl; double ui = 180.0 / acos(-1.0); cout << " 絶対値 " << abs(c1) << " 偏角 " << ui * arg(c1) << "度 ノルム " << norm(c1) << endl; cout << " 共役複素数 " << conj(c1) << " 極形式から複素数 " << polar(abs(c1), arg(c1)) << " リーマン球面への射影 " << proj(c1) << endl; // 数学関数の関数 c1 = {0.1, 0.2}; cout << "複素数 c1 : " << c1 << endl; complex<double> cs = cos(c1), sn = sin(c1), ta = tan(c1); cout << " cos " << cs << " sin " << sn << " tan " << ta << endl; cout << " acos " << acos(cs) << " asin " << asin(sn) << " atan " << atan(ta) << endl; complex<double> csh = cosh(c1), snh = sinh(c1), tah = tanh(c1); cout << " cosh " << csh << " sinh " << snh << " tanh " << tah << endl; cout << " acosh " << acosh(csh) << " asinh " << asinh(snh) << " atanh " << atanh(tah) << endl; cout << " pow " << pow(c1, 2) << " sqrt " << sqrt(pow(c1, 2)) << endl; cout << " exp " << exp(c1) << " log " << log(exp(c1)) << endl; cout << " pow " << pow(10, c1) << " log10 " << log10(pow(10, c1)) << endl; return 0; }
複素数 c1 : (1,1) real(メンバー関数) 1 real(関数) 1 メンバー関数で実部を変更 c1 : (2,1) 絶対値 2.23607 偏角 26.5651度 ノルム 5 共役複素数 (2,-1) 極形式から複素数 (2,1) リーマン球面への射影 (0.666667,0.333333) 複素数 c1 : (0.1,0.2) cos (1.01497,-0.0201001) sin (0.101837,0.20033) tan (0.0963881,0.199284) acos (0.1,0.2) asin (0.1,0.2) atan (0.1,0.2) cosh (0.984971,0.0199001) sinh (0.0981701,0.199664) tanh (0.103721,0.200614) acosh (0.1,0.2) asinh (0.1,0.2) atanh (0.1,0.2) pow (-0.03,0.04) sqrt (0.1,0.2) exp (1.08314,0.219564) log (0.1,0.2) pow (1.12777,0.559481) log10 (0.1,0.2)
菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |