## Unit-4

**Basic Math Calculations**

**Addition**

```
>> a=1; % Assign 1 to a
>> b=2; % Assign 2 to b
>> c=a+b % Skipping semicolon at the end displays the result
c =
3
```

**Subtraction**

```
>> d=a-b
d =
-1
```

**Multiplication**

```
>> e=a*b
e =
2
```

**Division**

```
>> a=23 % Skip the semicolon at the end to display the value
a =
23
>> b=5; % Type semicolon at the end to avoid displaying the value
>> c=a/b
c =
4.6000
>> d=rem(a,b)
d =
3
```

**Rounding Off Numbers – Floor**

```
>> c = 4.6;
>> floor(c) % Rounds off towards negative infinity
ans =
4
>> floor(-5.43) % Rounds off towards negative infinity
ans =
-6
```

**Rounding Off Numbers – Ceiling**

```
>> c = 4.6;
>> ceil(c) % Rounds off towards positive infinity
ans =
5
>> ceil(-5.43) % Rounds off towards positive infinity
ans =
-5
```

**Rounding Off Numbers – ***Round*

*Round*

```
>> round(-5.43) % Rounds off towards nearest integer
ans =
-5
>> round(5.43) % Rounds off towards nearest integer
ans =
5
>> round(5.5) % Rounds off towards nearest integer
ans =
6
```

**Rounding Off Numbers – ***Fix*

*Fix*

```
>> fix(-5.43) % Rounds off towards zero
ans =
-5
>> fix(5.5) % Rounds off towards zero
ans = 5
```

**Decimal Points**

```
>> a=22/7
a =
3.1429
>> format long
>> a=22/7
a =
3.142857142857143
>> format short
>> 22/7
ans =
3.1429
```

## Be the first to comment