矩阵的矩阵指数函数

If you haven’t already, I encourage you to read the

如果您还没有的话,建议您阅读

我的系列中的first article in my series to gain a basic foundation of R and R Studio.  You will also find the links for downloading the programs there as well.第一篇文章 ,旨在获得R和R Studio的基础知识。 您还将在此处找到用于下载程序的链接。

To begin, I want to mention a bit about the “packages” found in R.  The incredible thing about R is that is a dynamically evolving language that gains functionality on a daily basis.  Packages allow for anyone to compile functions and data sets together in one convenient bundle to extend to the base system functionality of R.  There are two main repositories that host packages, CRAN and bioconductor.  At the time of writing this article there are more than 9,000 individual packages available for use with R.

首先,我想谈一谈R中的“软件包”。R的不可思议之处在于,它是一种动态发展的语言,每天都在增加功能。 软件包允许任何人在一个方便的捆绑中一起编译功能和数据集,以扩展到R的基本系统功能。托管软件包的主要存储库有两个: CRAN和bioconductor 。 在撰写本文时,有超过9,000个单独的软件包可用于R。

A majority of the packages will be installed from CRAN, so I will highlight the steps to install and load packages hosted there.  The first thing you will need to do is to install the package, as an example we will install the ggplot2 (one of R’s most popular graphing packages).   Once you have the package installed, you must then load it.  The code is as follows:

大多数软件包将从CRAN安装,因此我将重点介绍安装和加载托管在此的软件包的步骤。 您需要做的第一件事是安装软件包,例如,我们将安装ggplot2 (R最受欢迎的图形软件包之一)。 一旦安装了软件包,就必须加载它。 代码如下:

install.packages("ggplot2")
library("ggplot2")

Alternatively, utilizing R Studio, you can click the Packages tab in the bottom right window, click install, and enter ggplot2 in the Packages field (seen below):

或者,可以使用R Studio单击右下窗口中的Packages选项卡,单击install,然后在Packages字段中输入ggplot2(如下所示):



Concept 1: Objects

概念1:对象

Now I would like to introduce you to a few of the functions and capabilities of R.  Starting from where I left off in Article 1, we were observing that R can be used as a calculator:

现在,我想向您介绍R的一些功能。从我在第1条中停止的地方开始,我们观察到R可以用作计算器:

2+2

Any time there is output in R, the result is assigned to a hidden named object .Last.value.  Objects are one of the biggest foundations to R’s amazing functionality.  Let’s try calling the object “Last value”

任何时候在R中输出时,结果都会分配给一个隐藏的命名对象.Last.value。 对象是R惊人功能的最大基础之一。 让我们尝试将对象称为“最后一个值”

.Last.value

As you can see, the output is the output from our last line of executed code.  This can come in handy later when you are performing multiple manipulations on different values.  Now, lets create out own object.

如您所见,输出是最后一行执行代码的输出。 当您对不同的值执行多种操作时,这可以派上用场。 现在,让我们创建自己的对象。

myobject <- 2+2
myobject
objects()
length(myobject)
is(myobject)

The assignment operator (<-, you can also use “=”) dictates that the proceeding text gets assigned the information that follows the operator.   I have also included the use of couple functions that return properties of the object.

赋值运算符(<-,您也可以使用“ =”)指示将继续文本分配给该运算符后面的信息。 我还使用了返回对象属性的耦合函数。

Concept 2: Functions

概念2:功能

Speaking of functions, lets take a look at some of the different built in functions of R.  You could call simple math functions:

说到函数,让我们看一下R的一些内置函数。您可以调用简单的数学函数:

sqrt(4)
sqrt(2+2)
sqrt(myobject)

Notice all of these functions return the same value.  There are multiple ways of manipulating data how best suits what you need with R.   However, take note:

请注意,所有这些函数都返回相同的值。 有多种方式处理数据,使其最适合您的R需求。但是,请注意:

sqrt(.Last.value)

Now returns sqrt(2) because the last value outputted was 2, not 4 anymore.  Keep that in mind if using a dynamic object like .Last.value.  The cool thing is, you can even perform mathematics on objects!

现在返回sqrt(2),因为最后输出的值是2,不再是4。 如果使用动态对象(如.Last.value),请记住这一点。 最酷的是,您甚至可以对对象执行数学运算!

(4*5)*myobject

Concept 3: Vectors

概念3:向量

Vectors in R are single entities consisting of an ordered collection of items.  To construct a vector you, the most common thing to do is to use the concatenate function c( ).  To do so, seperate every new element in the vector by a comma.  For example, you can have numeric vectors:

R中的向量是由项目的有序集合组成的单个实体。 要构造一个向量,最常见的做法是使用连接函数c()。 为此,请用逗号分隔向量中的每个新元素。 例如,您可以具有数字向量:

vector1 <- c(-10,-5,0,5,10)
vector1

The first line of code only defines the vector, the second will allow you to see the output in R’s console window.

代码的第一行仅定义向量,第二行将允许您在R的控制台窗口中查看输出。

This output brings up an interesting point I want to make.  The console window will output vectors, and other things like matrices and data sets, item by item.  The []1] on the left shows the position of the current element you are looking at.  So if for example, you have a vector of 100 elements, R will indicate to you which element starts the new row by a bracketed number (see the screenshot below for an example).

此输出提出了一个我想提出的有趣观点。 控制台窗口将逐项输出向量以及其他内容,例如矩阵和数据集。 左侧的[] 1]显示您正在查看的当前元素的位置。 因此,例如,如果您有一个由100个元素组成的向量,R将通过括号内的数字向您指示哪个元素开始新行(有关示例,请参见下面的屏幕截图)。

You can make vectors full of items that are other functions:

您可以使向量充满其他功能的项目:

vector2 <- c(abs(-17),3/4,sqrt(-3),log(0),10^3)
vector2

Or even make vectors of strings:

甚至制作字符串向量:

vector3 <- c(“Alpha”,”Beta”,”Gamma”)
vector3

Or have a vector with any combination of the former.  Operations for determining properties of the vector include:

或具有前者的任意组合的向量。 确定向量属性的操作包括:

mode(vector1)
range(vector1)
length(vector1)

Other ways of creating vectors includes using the sequence and repetition functions [seq() & rep()].  You just have to remember to pass the arguments for by what interval the sequence forms or how many times to repeat the item.

创建向量的其他方法包括使用序列和重复函数[seq()&rep()]。 您只需要记住将参数传递给序列形成的间隔或重复该项目的次数。

seq(3,30,3)
rep(c(0:2,4,8), 3)
rep(c(0:2,4,8), each=3)
rep(c("Hi", "Ho"), 3)
rep(c("Hi", "Ho"), each=3)
rep(c(T,F), 3)
rep(c(T,F), each=3)

Concept 4: Matrices

概念4:矩阵

Perhaps one of my personal favorite things to do in R is matrix manipulation.  Instead of having to put all my information into a matrix in my calculator I would rather use a program on the computer, like R, to carry out such calculations with ease.  And the wonderful thing is that R has some incredible capabilities.

在R中我个人最喜欢做的事情之一可能是矩阵处理。 不必将我所有的信息放入计算器中的矩阵中,我宁愿使用计算机上的程序(如R)轻松进行此类计算。 令人惊奇的是R具有一些不可思议的功能。

So lets make our first matrix:

因此,让我们建立第一个矩阵:

m1 <- matrix(1:10, ncol =2)
m1

Notice to populate the matrix I chose a sequence of number between 1 and 10, that is the 1:10 operation, and defined the number of columns I wanted, ncol=2.  The output is displayed in a way that makes sense:

注意,要填充矩阵,我选择了一个1到10之间的数字序列,即1:10运算,并定义了我想要的列数ncol = 2。 以有意义的方式显示输出:

Where the bracketed numbers on the left show the row position and the bracketed numbers on the top show the column position.  Combined, this means that []3,2] is the element in row 3 column 2, which in our case is 8.  We could also use the power of R to have it output this answer to us:

左边的括号内的数字表示行位置,顶部的括号内的数字表示列位置。 组合起来,这意味着[] 3,2]是第3行第2列的元素,在我们的例子中是8。我们还可以使用R的幂将其输出给我们:

m1[3,2]

Or we can extract entire rows or columns:

或者我们可以提取整个行或列:

m1[3,]
m1[c(4,5),]

Pretty trivial now, but could come in handy when you have large matrices and you need to perform operations on a specific element, row, or column.

现在非常琐碎,但是当您有大型矩​​阵并且需要对特定元素,行或列执行操作时,它可能会派上用场。

It is important to mention there are some very handy arguments the matrix function can take, I will show you them in the following steps but for future reference you can call the help() function to see the types of arguments functions can take, for example if we need help with the matrix function:

重要的是要提到矩阵函数可以接受一些非常方便的参数,我将在以下步骤中向您展示它们,但是为了将来参考,您可以调用help()函数以查看函数可以接受的参数类型,例如如果我们需要有关矩阵功能的帮助:

help(“matrix”)

I digress.  Back to matrices.  Here are some more examples of how to construct, index, and manipulate matrix elements:

我离题了。 回到矩阵。 以下是一些有关如何构造,索引和操作矩阵元素的示例:

m2 <- matrix(1:10, nrow=2, byrow = TRUE)
m2
m3 <- matrix(1:12, ncol=4, byrow=TRUE)
m3
m3[3,]
m3 [,c(2,4)]
m3 [c(1,3),c(2,4)]
m3 [3,4] <- 0
m3

Concept 5: Operators and Functions Using Matrices

概念5:使用矩阵的运算符和函数

Consider the square matrix:

考虑方阵:

m4 <- matrix(1:9,nrow=3)
m4

We can perform some operations with this matrix such as the transpose, adding a constant to the matrix, multiplying by a constant, adding two matrices, multiplying by a vector or another matrix (listed respective order below):

我们可以对此矩阵执行一些操作,例如转置,将常数添加到矩阵,乘以常数,添加两个矩阵,乘以向量或另一个矩阵(下面列出了相应的顺序):

t(m4)m4 + 10m4 * 4m5 <- t(m4)
m4 + m5v1 <- 1:3
v1m4 * v1
m4 * m5

All of these looking similar to normal mathematics, but say you want to use matrix multiplication, you need to use a special command:

所有这些看起来都与普通的数学相似,但是说您要使用矩阵乘法,需要使用特殊的命令:

m4 %*% m5

If you notice, using an asterisk (*) and using the matrix multiplication (%*%) provide different answers.  Be careful you use the correct one!

如果您注意到,使用星号(*)和矩阵乘法(%*%)提供不同的答案。 注意使用正确的!

We can also create a diagonal matrix, take the inverse of a matrix, or find the determinant:

我们还可以创建一个对角矩阵,取矩阵的逆矩阵,或找到行列式:

diag(c(3,2,1))
solve(matrix(c(8,9,6,7),nrow=2))
det(matrix(c(8,9,6,7),nrow=2))

I encourage you to explore some of these different operations and functionalities yourself.  There are so many things I haven’t touch upon that utilize these basic concepts but if you have any questions about what I have mentioned or how to go more in-depth, please leave a comment.

我鼓励您自己探索其中一些不同的操作和功能。 利用这些基本概念,我有很多事情没有涉及,但是如果您对我提到的内容或如何进行更深入的了解有任何疑问,请发表评论。

Also I would like to mention if there are any functionalities you would like to see in my upcoming articles, please let me know!

另外,我想提及的是,如果您希望在以后的文章中看到任何功能,请告诉我!

翻译自: https://www.experts-exchange.com/articles/19199/Mastering-R-Programming-Using-Packages-Creating-Objects-and-Basic-Matrix-Functions.html

矩阵的矩阵指数函数

矩阵的矩阵指数函数_精通R编程:使用包,创建对象和基本矩阵函数相关推荐

  1. r语言 bsda包_使用R语言creditmodel包进行Vintage分析或留存率分析

    1 什么是vintage分析? Vintage分析(账龄分析法)被广泛应用于信用卡及信贷行业,这个概念起源于葡萄酒,即不同年份出产的葡萄酒的品质有差异,那么不同时期开户或者放款的资产质量也有差异,其核 ...

  2. python包里面的dll是什么_使用R的程序包提示我们无法使用怎么回事?因为计算机丢失jvm.dll...

    R是用于统计分析.绘图的语言和操作环境.R是属于GNU系统的一个自由.免费.源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具.目前数据挖掘领域里面R是比较流行的统计软件,因为其免费的特性赢得 ...

  3. r 字符串转化为数值_【R语言】数据结构Ⅰ—向量,矩阵,数组

    数据结构是为了便于存储不同类型的数据而设计的. R中常用的数据结构包括: 同质数据类型(homogeneous data types),即所存储的一定是相同类型的元素,包括向量.矩阵.数组: 异质数据 ...

  4. python 矩阵除法_请问matlab编程,怎样让两个矩阵对应元素相除?

    展开全部 >> clear >> A=[3 6 9]; >> B=[1 2 3]; >> C=A./B C = 3 3 3 注: MATLAB在矩阵的运 ...

  5. numpy 矩阵与向量相乘_高能!8段代码演示Numpy数据运算的神操作

    作者|王天庆 来源|大数据(ID:hzdashuju) 导读:本文介绍一下在Python科学计算中非常重要的一个库--Numpy. Numpy是Numerical Python extensions ...

  6. matlab 判断两个矩阵有元素相等_如何使用MATLAB对Excel中的多参数进行计算?

    THE START MATLAB和Excel这两者之间有着什么样的关系呢?今天我把之前学习以及用到的关于用MATLAB读写Excel数据,并进行计算处理的经验分享给需要的小伙伴.参加过数学建模的这个应 ...

  7. 单目初始化 单应矩阵 本质矩阵 恢复R t 三角变换求 3D点

    单目初始化 单应矩阵 本质矩阵 恢复R t 三角变换求 3D点 博文末尾支持二维码赞赏哦 ^_^ /* * This file is part of ORB-SLAM2 * * 单目相机初始化 * 用 ...

  8. 二阶矩阵转置怎么求_矩阵求导术(下)

    本文承接上篇 https://zhuanlan.zhihu.com/p/24709748,来讲矩阵对矩阵的求导术.使用小写字母x表示标量,粗体小写字母 表示列向量,大写字母X表示矩阵.矩阵对矩阵的求导 ...

  9. 矩阵迹的性质_机器学习的数学基础 之 矩阵范数 — 我的长度我做主?

    热点追踪 / 数学基础 / 编程基础 / 实战技术 字数: 3925 作者: 小组成员机器学习与数学 出品 0x01.矩阵的诞生 在数学史上,矩阵的概念提出得比较晚,但可以朔源到两千多年前就提出的线性 ...

  10. matlab矩阵半张量积,矩阵的半张量积_一个便捷的新工具.pdf

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp高等教育&nbsp>&nbsp微积分 矩阵的半张量积_一个便捷的新工具.pdf11页 本文档 ...

最新文章

  1. Java 读取 dwg 转换 dxf
  2. IDEA界面太丑??尝试一下这几个插件!
  3. 数据库——MongoDB增删改查
  4. spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误
  5. 修改elementUI组件样式无效的多种解决方式
  6. 利用计算机卸载,电脑使用痕迹彻底清理工具(无影无踪WYWZ)
  7. pymavlink 源码剖析(一)之XML文件的数据解析
  8. Java 8整装待发 图谋云计算
  9. 45. Use member function templates to accept all compatible types.
  10. maven依赖包快速下载
  11. Android逆向不可不知的smali语言
  12. 【APP加载H5页面加载流程概述及提速方案】
  13. 组合导航GPS+IMU
  14. 云服务器ECS的基本概念
  15. java macd指标_Java 验证 MACD 底背离是否真的有效
  16. 微信H5页面图片上传避坑指南(vant+vue)
  17. 实验三:基于A*算法的迷宫
  18. linux下获取按键响应事件(转)
  19. 计算机网络原理 笔记整理
  20. python wechatsougou_python 使用qq登陆搜狗微信搜索

热门文章

  1. pyodbc linux 乱码,python-无法在Linux上安装pyodbc
  2. Cloudcompare2.12.2使用vs2022带插件编译以及在WSL中编译cloudCompare【最新实践】
  3. JTT808/1078管理平台发布
  4. Mybatis 传入多个参数查询数据 (3种方法)
  5. 1.Excel绘制斜线表头
  6. python怎么识别拼音-python+拼音
  7. Mac上如何提取解压pkg文件
  8. 计算机专业找工作面试面经总结
  9. Android 系统字体
  10. 搭建开源物联网平台教程