E002

调用orsci中的vint和vdouble类型的基本向量操作。

 

// E002
//http://www.orsci.cn
//功能:演示向量vector的基本操作

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#include "orsciVM.h"
using namespace orsci; //orsci包的命名空间。

int _tmain(int argc, _TCHAR* argv[])
{
cout << "E002:向量的基本操作!http://www.orsci.cn" << endl;
{ //整数向量vint展示
vint a, b;
a = "1:10";
cout << a << endl;
b.resize(5);
for (int k = 0; k < b.size(); k ++)
{
b(k) = k;
}
cout << b << endl;
}
{ //浮点向量vdouble展示
vdouble x, y;
x = "1, 2, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 11, 15";
cout << "x = " << x << endl;
cout << "最小值:" << vmt::minv(x) << endl;
cout << "最大值:" << vmt::maxv(x) << endl;
cout << " 求和:" << vmt::sum(x) << endl;
cout << " 均值:" << vmt::mean(x) << endl;
cout << "样本方差:" << vmt::var(x) << endl;
cout << " 中位数:" << vmt::median(x) << endl;
cout << "峰度系数:" << vmt::kurtousis(x) << endl;
cout << "偏度系数:" << vmt::skewness(x) << endl;
cout << "第1四分位数:" << vmt::quartiles(x, 1) << endl;
cout << "第2四分位数:" << vmt::quartiles(x, 2) << endl;
cout << "第3四分位数:" << vmt::quartiles(x, 3) << endl;
cout << "五数概括:" << vmt::fiveNumber(x) << endl;

y = x * 2;
cout << "x * 2 = " << y << endl;
cout << "x + x = " << x + x << endl;

vdouble z;
z = "1:5, 12, 16"; //注:1:5代表从1到5
cout << z << endl;
z = "2:3:10"; //注:"2:3:10"代表从2开始的序列,按3递增,直到不超过10。
cout << z << endl;
}
cout << "Press any key to continue...";
char pp;
cin >> pp;
return 0;
}

输出

E002:向量的基本操作!http://www.orsci.cn
1 2 3 4 5 6 7 8 9 10
0 1 2 3 4
x = 1 2 4 5 5 6 6 6 7 7 8 8 9 11 15
最小值:1
最大值:15
求和:100
均值:6.66667
样本方差:11.8095
中位数:6
峰度系数:1.57546
偏度系数:0.741023
第1四分位数:5
第2四分位数:6
第3四分位数:8
五数概括:1 15 5 6 8
x * 2 = 2 4 8 10 10 12 12 12 14 14 16 16 18 22 30
x + x = 2 4 8 10 10 12 12 12 14 14 16 16 18 22 30
1 2 3 4 5 12 16
2 5 8

参考 姜维. 《数据分析与数据挖掘》。程序orsci开发包(C++语言)。