arithmetic and logical operators
DESCRIPTION
Matlab and simulink labTRANSCRIPT
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)
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.
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 (|)
Result: