欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > c++精解【5】

c++精解【5】

2024/10/26 7:25:11 来源:https://blog.csdn.net/sakura_sea/article/details/139905288  浏览:    关键词:c++精解【5】

文章目录

  • Eigen
    • 矩阵元素定义
    • 矩阵加法
    • 矩阵乘法
    • 向量
    • 编译时设置大小
  • poco
    • 名言
    • 基础

Eigen

矩阵元素定义

  • 定义每个元素值
    [ 1 3 2 4 ] \begin{bmatrix} 1& 3 \\2& 4 \end{bmatrix} [1234]
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;int main()
{MatrixXd m(2,2);m(0,0) = 1;m(1,0) = 2;m(0,1) = 3;m(1,1) = 4;std::cout << m << std::endl;
}
1 3
2 4Process returned 0 (0x0)   execution time : 0.151 s
Press any key to continue.
  • 随机矩阵
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;int main()
{MatrixXd m = MatrixXd::Random(2,2);std::cout << m << std::endl;
}
-0.997497 -0.6133920.127171  0.617481Process returned 0 (0x0)   execution time : 0.110 s
Press any key to continue.

矩阵加法

MatrixXd::Constant(4,4,10)是一个4*4的矩阵(方阵),每个元素都是10.

#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;int main()
{MatrixXd m = MatrixXd::Random(4,4);std::cout << m << std::endl;m = (m + MatrixXd::Constant(4,4,10));std::cout << m << std::endl;
}
 -0.997497   0.170019    0.64568   0.4210030.127171 -0.0402539    0.49321  0.0270699-0.613392  -0.299417  -0.651784   -0.392010.617481   0.791925   0.717887  -0.9700319.0025   10.17 10.6457  10.421
10.1272 9.95975 10.4932 10.0271
9.38661 9.70058 9.34822 9.60799
10.6175 10.7919 10.7179 9.02997Process returned 0 (0x0)   execution time : 0.042 s
Press any key to continue.
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;int main()
{MatrixXd m = MatrixXd::Random(4,2);std::cout << m << std::endl;m = m + MatrixXd::Constant(4,2,10);std::cout << m << std::endl;
}
 -0.997497   0.1700190.127171 -0.0402539-0.613392  -0.2994170.617481   0.7919259.0025   10.17
10.1272 9.95975
9.38661 9.70058
10.6175 10.7919Process returned 0 (0x0)   execution time : 0.114 s
Press any key to continue.

矩阵乘法

MatrixXd::Constant(2,4,10)是一个2*4的矩阵(方阵),每个元素都是10.

#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;int main()
{MatrixXd m = MatrixXd::Random(4,2);std::cout << m << std::endl;m = m * MatrixXd::Constant(2,4,10);std::cout << m << std::endl;
}
 -0.997497   0.1700190.127171 -0.0402539-0.613392  -0.2994170.617481   0.791925
-8.27479 -8.27479 -8.27479 -8.27479
0.869167 0.869167 0.869167 0.869167
-9.12809 -9.12809 -9.12809 -9.1280914.0941  14.0941  14.0941  14.0941Process returned 0 (0x0)   execution time : 0.291 s
Press any key to continue.

向量

  • VectorXd
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;
using Eigen::VectorXd;
using namespace std;
int main()
{MatrixXd m = MatrixXd::Random(3,3);VectorXd v(3);v << 10, 20, 30;cout << "v =" << endl <<  v << endl;cout << "m * v =" << endl << m * v << endl;
}
v =
10
20
30
m * v =
-6.6078728.429812.4314Process returned 0 (0x0)   execution time : 0.167 s
Press any key to continue.
  • MatrixXd
    可使用矩阵函数定义向量
#include <iostream>
#include "f:/learn/eigen-3.4.0/Eigen/Dense"using Eigen::MatrixXd;
using Eigen::VectorXd;
using namespace std;
int main()
{MatrixXd m = MatrixXd::Random(3,3);MatrixXd v(3,1);v(0,0) = 10;v(1,0) = 20;v(2,0) = 30;cout << "v =" << endl <<  v << endl;cout << "m * v =" << endl << m * v << endl;
}

编译时设置大小

本节前面的例子都是在运行时动态设置矩阵size,下面的例子是在编译时设置

#include <iostream>
#include <Eigen/Dense>using Eigen::Matrix3d;
using Eigen::Vector3d;int main()
{Matrix3d m = Matrix3d::Random();m = (m + Matrix3d::Constant(1.2)) * 50;std::cout << "m =" << std::endl << m << std::endl;Vector3d v(1,2,3);std::cout << "m * v =" << std::endl << m * v << std::endl;
}

poco

名言

“没有好的库,感兴趣的任务很难在c++中完成; 但如果有一个好的库,几乎任何任务可以变得简单。”
–Bjarne Stroustrup(c++的设计者和原始实现者)

基础

  • POCO c++库是功能强大的跨平台开源c++库,用于构建运行在桌面、服务器、移动、物联网和嵌入式系统上的基于网络和互联网的应用程序。

  • POCO c++库项目于2004年由g<s:1> nter Obiltschnig(应用信息学/ machine .io)启动。当时,c++的受欢迎程度正迅速达到绝对低点,因为几乎所有人都在追随托管和基于虚拟机的编程语言的趋势。然而,g<s:1> nter相信c++。他想创建一套全面的库,涵盖所有现代编程需求。对于他自己来说,对于其他c++程序员来说也是如此,他们正在努力寻找高质量和易于使用的c++库来进行网络编程、XML(以及后来的JSON)处理、数据库访问以及几乎每个现代应用程序都需要的所有其他功能。

  • 2005年2月发布了c++可移植组件(这是当时的叫法,也是POCO名称的由来)的第一个版本。在第一个版本发布后不久,Aleksandar Fabijanic (Aleph ONE)加入了g<s:1> nter,他一直是贡献者和合作项目的负责人。从一开始,已有超过180名开发人员为POCO c++库贡献了代码。

  • POCO已在全球数百个(如果不是数千个)项目中使用,并部署在数百万台设备中。无论是楼宇自动化系统、工业自动化、物联网平台、空中交通管理系统、企业IT应用和基础设施管理、安全和网络分析、汽车信息娱乐和远程信息处理、金融或医疗保健,c++开发人员都一直在使用POCO c++库进行具有挑战性和关键任务的应用。

  • 用高效、现代的ANSI/ISO标准c++编写c++标准库/STL;

  • 高度可移植,可在许多不同的平台上使用;

  • 开放源码,在Boost软件许可证下许可,因此商业和非商业用途都是完全免费的。

Boost 软件许可证 1.0

别名:Boost 软件许可协议 1.0,BSL-1.0 许可证/许可协议

BSL-1.0
是一个简单的宽容许可证,仅需要保留版权和许可声明来分发资源(非二进制)。许可的作品、修改和更大的作品能够以不同的许可协议分发,并且可以不提供源代码。
完整协议: BSL-1.0

  • 支持平台

Microsoft Windows
Linux
Mac OS X
HP-UX, Solaris, AIX*
Embedded Linux (uClibc, glibc)
iOS
Windows Embedded CE
QNX

  • 安装
$ git clone -b poco-1.13.3-release https://github.com/pocoproject/poco.git
  • 更多见poco官网

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com