Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

cos

以弧度为单位的参数的余弦

说明

Y = cos(X) 返回 X 的每个元素的余弦。cos 函数按元素处理数组。该函数同时接受实数和复数输入。

  • 对于 X 的实数值,cos(X) 返回区间 [-1, 1] 内的实数值。

  • 对于 X 的复数值,cos(X) 返回复数值。

示例

全部折叠

在域 -πxπ 上绘制余弦函数。

x = -pi:0.01:pi; 
plot(x,cos(x))
grid on

Figure contains an axes object. The axes object contains an object of type line.

计算复角在向量 x 中的余弦。

x = [-i pi+i*pi/2 -1+i*4];
y = cos(x)
y = 1×3 complex

   1.5431 + 0.0000i  -2.5092 - 0.0000i  14.7547 +22.9637i

输入参数

全部折叠

以弧度为单位的输入角度,指定为标量、向量、矩阵、多维数组、表或时间表。

数据类型: single | double | table | timetable
复数支持:

输出参数

全部折叠

输入角的余弦,以实数值或复数值标量、向量、矩阵或多维数组、表或时间表形式返回。

详细信息

全部折叠

余弦函数

通过引用直角三角形定义的角的余弦 α 是

cos(α)=adjacent sidehypotenuse=bh.

Right triangle with vertices A, B, and C. The vertex A has an angle α, and the vertex C has a right angle. The hypotenuse, or side AB, is labeled as h. The opposite side of α, or side BC, is labeled as a. The adjacent side of α, or side AC, is labeled as b. The cosine of α is defined as the adjacent side b divided by the hypotenuse h.

复数参数的余弦 α 是

cos(α)=eiα+eiα2.

提示

  • 要精确计算 cos(X*pi) 而不使用 pi 作为 π 的浮点近似值,您可以改用 cospi 函数。例如,对于奇数 mcospi(m/2) 精确为零;对于整数 ncospi(n) 为 +1 或 -1。

扩展功能

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

GPU 代码生成
使用 GPU Coder™ 为 NVIDIA® GPU 生成 CUDA® 代码。

版本历史记录

在 R2006a 之前推出

全部展开

另请参阅

| | | |