MATLAB 4

# MATLAB 4 - Matlab 4 Even or Odd What for Tian Gu ID...

This preview shows pages 1–2. Sign up to view the full content.

1 Matlab 4 Even or Odd? What for? Tian Gu ID: 853324472 Team partner: Tielong Su The Modulus Function – mod About the new function ‘mod’ We try to use ‘help’ and ‘doc’ to find the what mod does. Modulus after division is the definition in help and doc. But we are still confused about the descriptions. And what exactly modulus is? Then we use search Modulo operation by Wikipedia. It gives the description of remainder’ which is more easily to understand. We connected the examples in ‘help’ and ‘doc’. So we think this new function is used to get the remainder of division. Looking back to the examples in ‘doc’, now we try to explain them. Example 1: mod(13,5) ans = 3 Here, 13 is the dividend, and 5 is the divisor, we use the function ‘mod(13,5)’ to find the remainder of this division is 3. Comparing to the example which the guide gives us, we can find they are similar. >> mod(8,3) ans = 2 8 is the dividend, and 3 is the divisor (8/3). So, we get the remainder 2. Example 2: mod([1:5],3) ans = 1 2 0 1 2 This example in ‘doc’ is a little different. [1:5] is the dividend. So what we do is using 1~5 as the dividend one after another. Finally we can find all remainders. Even or Odd The program we need to write is distinguish if an integer is odd or even. We should make the user input a integer, so we start with, numb = input('Please input an integer number:','s'); We can use the new function ‘mod’ to indentify the integer according the reminder of dividing the number by 2. rem = mod(numb,2);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

MATLAB 4 - Matlab 4 Even or Odd What for Tian Gu ID...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online