arithmetic and logical operators

5
Arithmetic operators: 1. The variables x,y,z have the values 2.5, 0.5, and 2 respetively. Evaluate the following matlab expressions. a. x+y+z b. x*y*z c. x/y d. x y e. x z 2. The complex variables are x=3-4i and y=1+2i. Evaluate the following Expressions a. x+y b. x-y c. x*y d. x y 3. Evaluate the fllowing ogical operations. a) (a == 1) & (b == 2) b) (a == 2) & (b == 2) c) (a == 2) | (b == 2) d) a & b e) ~a f) c = 0 g) ~c h) (~b) | (~c) 4. Evaluate the program in matlab. And verify the result a. number=3; if (number == 1) disp(‘The number is 1’); elseif (number == 2) disp(‘The number is 2’); else disp(‘The number is not 1 or 2’); end; b. (number == 7) | (number == 11)

Upload: apecevsb

Post on 12-Jul-2016

228 views

Category:

Documents


1 download

DESCRIPTION

Matlab and simulink lab

TRANSCRIPT

Page 1: Arithmetic and Logical operators

Arithmetic operators:

1. The variables x,y,z have the values 2.5, 0.5, and 2 respetively. Evaluate the following matlab expressions.a. x+y+zb. x*y*zc. x/yd. xy

e. xz

2. The complex variables are x=3-4i and y=1+2i. Evaluate the following Expressionsa. x+yb. x-yc. x*yd. xy

3. Evaluate the fllowing ogical operations.a) (a == 1) & (b == 2) b) (a == 2) & (b == 2) c) (a == 2) | (b == 2) d) a & b e) ~a f) c = 0g) ~c h) (~b) | (~c)

4. Evaluate the program in matlab. And verify the resulta. number=3;

if (number == 1) disp(‘The number is 1’);

elseif (number == 2) disp(‘The number is 2’); else disp(‘The number is not 1 or 2’); end;

b. (number == 7) | (number == 11)

Page 2: Arithmetic and Logical operators

Expt.No. Arithmetic and Logical Operators

Date:

Aim:

To know and understand the basic Arithmetic and logical operators in Matlab tool.

Softwares Required:

Matlab R2015a

Hardware Required:

A personnel Computer.

Procedures:

1. Open matlab File.2. Type the program in the editor window.3. Save the file with .m Extension and run the program.4. Verify the output in the command Window.

Theory:

Arithmetic Operators: Performs arithmetic computations like addition, Subtraction , multiplication etc.

Page 3: Arithmetic and Logical operators

Logical Operators: Performs logical operators like AND,OR,NOT etc.

The operands for the logical operators need to be logical and can assume the values TRUE expressed as ‘1’ and FALSE expressed as ‘0’. If the operand has numerical values, then MATLAB takes non zero values as TRUE.

& And| Or~ Not

xor() Exorany() True if any element of vector is non-zeroall() True if all element of vector are non zero

Hierarchy of Operators:

1. Parenthesis ()2. Transpose (.’),Power (.^), Complex conjugate (‘), Matrix Power (^)3. Unary plus (+),Unary minus (-), Logical NOR (~)4. Multiplication (.*), Right Division (./),Left Division(.\), Matrix Multiplication (*),

Matrix right division (/),Matrix left division (\)5. Addition (+), Subtraction (-)6. Colon Operator (:)7. Less than (<),Less than equal to (<=),Greater than (>),Greater than equal to(>=),equal

to (= =),Not equal to (–=)8. Logical AND (&)9. Logical OR (|)

Page 4: Arithmetic and Logical operators

Result: