【 MATLAB 】mod 函数介绍

您所在的位置:网站首页 mod函数的 【 MATLAB 】mod 函数介绍

【 MATLAB 】mod 函数介绍

2024-07-18 07:53:26| 来源: 网络整理| 查看: 265

mod

Remainder after division (modulo operation)

除法(模运算)之后的余数

Syntax

b = mod(a,m)

Description

b = mod(a,m) returns the remainder after division of a by m, where a is the dividend and m is the divisor. This function is often called the modulo operation, which can be expressed as b = a - m.*floor(a./m). The mod function follows the convention that mod(a,0) returns a.

b = mod(a,m)返回a除以m后的余数,其中a是被除数,m是除数。此函数通常称为模运算,可表示为 b = a - m.*floor(a./m)。 mod函数遵循mod(a,0)返回a的约定。

Remainder After Division of Scalar % Remainder After Division of Scalar % Compute 23 modulo 5. b = mod(23,5)

b = 3;

Remainder After Division of Vector

Find the remainder after division for a vector of integers and the divisor 3.

a = 1:5; m = 3; b = mod(a,m) b = 1×5 1 2 0 1 2 Remainder After Division for Positive and Negative Values

Find the remainder after division for a set of integers including both positive and negative values. Note that nonzero results are always positive if the divisor is positive.

在除法之后找到一组整数,包括正值和负值。 请注意,如果除数为正,则非零结果始终为正。

a = [-4 -1 7 9]; m = 3; b = mod(a,m) b = 1×4 2 2 1 0

注:这里说明下负数如何对一个正数取模,或者做mod运算,例如求:

mod(-4,3),算法流程是这样的,先根据3对负数进行处理,即-4+3+3=2,这样就处理成了正数,然后在取余运算,mod(2,3)=2。

同理,mod(-1,3),先将-1+3 = 2,之后mod(2,3)=2.

至于为什么要加3,我们不妨认为对谁取余,例如mod(a,m),a /m = n ...b,也就是a除以m得到n余b,那么a = m * n + b,我们需要求得是b,从这个式子中我们可以看出,a加上几个m之后再除以m,是不影响b的值的,所以这种处理是可以的。

Remainder After Division for Negative Divisor

Find the remainder after division by a negative divisor for a set of integers including both positive and negative values. Note that nonzero results are always negative if the divisor is negative.

在除法之后找到一个负除数,得到一组整数,包括正值和负值。 请注意,如果除数为负,则非零结果始终为负。

a = [-4 -1 7 9]; m = -3; b = mod(a,m) b = 1×4 -1 -1 -2 0 注:花里胡哨的,处理的方法和被除数a是负数时原理一样,这时,如果a是正数,则对a加几个m之后变成负数,在对m取余。 Remainder After Division for Floating-Point Values

Find the remainder after division for several angles using a modulus of 2*pi. Note that mod attempts to compensate for floating-point round-off effects to produce exact integer results when possible.

使用2 * pi的模数找到除法后的几个角度的余数。 请注意,mod会尝试补偿浮点舍入效果,以便在可能的情况下生成精确的整数结果。

theta = [0.0 3.5 5.9 6.2 9.0 4*pi]; m = 2*pi; b = mod(theta,m) b = 1×6 0 3.5000 5.9000 6.2000 2.7168 0

注:除数是浮点数而已,按照MATLAB能处理的精度算就是了,让它算。

Differences Between mod and rem

The concept of remainder after division is not uniquely defined, and the two functions mod and rem each compute a different variation. The mod function produces a result that is either zero or has the same sign as the divisor. The rem function produces a result that is either zero or has the same sign as the dividend.

除法后的余数的概念不是唯一定义的,并且两个函数mod和rem各自计算不同的变化。 mod函数产生的结果为零或与除数具有相同的符号。 rem函数产生的结果为零或与被除数具有相同的符号。

Another difference is the convention when the divisor is zero. The mod function follows the convention that mod(a,0) returns a, whereas the rem function follows the convention that rem(a,0)returns NaN.

另一个区别是除数为零时的约定。 mod函数遵循mod(a,0)返回a的约定,而rem函数遵循rem(a,0)返回NaN的约定。

Both variants have their uses. For example, in signal processing, the mod function is useful in the context of periodic signals because its output is periodic (with period equal to the divisor).

两种变体都有其用途。 例如,在信号处理中,mod函数在周期信号的上下文中是有用的,因为它的输出是周期性的(周期等于除数)。

Congruence Relationships

同余关系

The mod function is useful for congruence relationships: a and b are congruent (mod m) if and only if mod(a,m) == mod(b,m). For example, 23 and 13 are congruent (mod 5).

mod函数对于同余关系很有用:当且仅当mod(a,m)== mod(b,m)时,a和b是全等的(mod m)。 例如,23和13是一致的(模5)。

 

 

 

 



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


    图片新闻

    实验室药品柜的特性有哪些
    实验室药品柜是实验室家具的重要组成部分之一,主要
    小学科学实验中有哪些教学
    计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
    实验室各种仪器原理动图讲
    1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
    高中化学常见仪器及实验装
    1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
    微生物操作主要设备和器具
    今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
    浅谈通风柜使用基本常识
     众所周知,通风柜功能中最主要的就是排气功能。在

    专题文章

      CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭