The REM () and mod () functions of MATLAB

Source: Internet
Author: User
The REM () and mod () functions of MATLAB

REM (x, y): to divide the remainder of X/y

MoD (x, y): modulo

REM (x, y) =x-y.*fix (x./y); (fix () rounding to 0)

MoD (x, y) =x-y.*floor (x./y); (Floor () rounding left)

If x and y are the same symbol (same as ' + ', same as '-'), then REM (x, y) =mod (x, y) (positive and positive, negative and negative, rounding results two function effects)

If the sign of x and Y is reversed, then mod (x, y) =rem (x, y) +y (positive and negative numbers are rounded to see what you want to do with the function you choose)

When the positive and negative values are taken, the sign of the resulting remainder is expected to be the same as the divisor (x), with the REM () function; When the resulting remainder of the symbol wants to be the same as the divisor (y), use the MoD () function

For example:

REM (3,2) =1;mod (3,2) = 1;

REM ( -3,-2) =-1;mod ( -3,-2) =-1;

REM (3,-2) =1;mod (3,-2) =-1;

REM ( -3,2) =-1;mod ( -3,2) = 1;

MoD (3,2) =rem (3,2) = 1;

MoD (3,-2) =rem (3,-2) -2=1-2=-1;

MoD ( -3,2) =rem ( -3,2) +2=-1+2=1;

The REM () and mod () functions of MATLAB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.