Course Title : Numerical Technique Lab
Course Code : EEE 314L
Instructor : Istiak Ahmed
Independent Experiment No. : 01
Experiment Name : Introduction to
University,
Bangladesh Department of MATLAB OBJECTIVE:
Electrical and Electronic Engineering Name: Tanvir Al Radoen
ID:2030625
Sec:01
BAETE Accredited
• To get introduced with basic MATLAB command on matrix operations
• Perform different matrix operations on given examples.
# MATLAB works with three types of windows on your computer screen. These are the Command
window, the Figure window and the Editor window. The Figure window only pops up whenever
you plot something. The Editor window is used for writing and editing MATLAB programs (called
M files)
# From the "New Script" menu start a new m-file. Always write your program in m-file & save it.
The file/function/variable name must start with a letter and cannot contain space. The name can be a
mix of letters, digits, and underscores. (e.g., vector_A, but not vector-A (since "-" is a reserved char).
must not be longer than 31 characters
# You can also write any command or program in "command window".
# Function "clear all" removes all variables, globals and functions. Write clear all at the beginning
of your m-file.
# Write "clc" in command window to clear the command window
# MATLAB is case sensitive. e.g., NAME, Name, name are 3 distinct variables. # Write "help
function_name" in command window after the ">>" sign to see the description of the function.
For example, type "help sin" to know about sin functions in MATLAB. You can also use help in
the menubar.
Explore MATLAB‟s lookfor and help capability by trying the following:
>> lookfor keywords
>> help
>> help plot
>> help ops
>> help arith
Special Characters:
There are a number of special reserved characters used in MATLAB for various purposes. Some of
these are used as arithmetic operators, namely, +. -, *, /. While others perform a multitude of
purposes:
∙ %: Anything after % (and until the end of line) is treated as comments
Example: x = 1:2:9; % x = [ 1 3 5 7 9]
∙ ; delimits statements; suppresses screen output
Example: x = 1:3: 12; y = 2: 10; % two statements on the same line
∙ : range delimiter
Example: x = 1:2:9; % x = [ 1 3 5 7 9]
∙ ' matrix transposition
Example: x = [1:2:9] ' % x changed from row vector to column vector
∙ , command delimiter
Example: x = 1:2:9, y = 2:10, % two statements on the same line
∙ . precede an arithmetic operator to perform an elemental operation instead of matrix
operation
Example: x = 3:3:9
x=369
y = 3* ones (1,3)
y=333
z = x./y
z=123
Arithmatic Operations and Built in functions:
Example 1: Find y = exp(52/ 3pi).
Solution: The m-file write the following command
clear all;
a = 5^2;
b = 3*pi;
y = exp(a/b);
disp(y)
Matrices:
# Write A = [ 1 2 3; 4 5 6; 7 8 9] in command window and press “enter’’. It is a 3 × 3 matrix.
# Write A(1,3) in command window to view the third element in 1st row. The first parameter within
bracket denotes row and the second parameter denotes column
# Z = zeros(2,3) creates a 2 × 3 matrix of zeros.
Additional Commands
(��× ��) Matrix whose sum from any angle is magic(n)
same
(��× ��) Random matrix rand(n)
(��× ��) Matrix whose elements are one ones(n)
Inverse of matrix A inv(A)
(��× ��) matrix whose diagonal are one eye(n)
Diagonal element of matrix ‘A’ diag(A)
# Write A = 0:0.3:3 in the command window. 0 is the starting value, 3 is the end value and 0.3 is the
step value.
# Write “help size”, “help length” and “help numel” in command window.
# Matrix Operations:
# All arithmetic operations can be performed on matrices
# Operations can be performed on each element or on whole matrix. For
example, x = 3:3:9;
y = 3* ones (1,3);
z = x./y
# +. -, *, /, ^ (algebraic/matrix definitions)
.+ .- .* ./ .^ (element by element operation)
Lab Works:
1. Find the value of y = ln(sinh(exp(54/6* last digit of your ID)
2. Find the size, length and number of elements of following matrices
A = [ 1 2 3; ‘last digit of your ID’ 5 6; 8 9 12; 64 56 78]
B = [7:1:13; 7:2:19]
3. A = [‘last digit of your ID’ 3; 4 5]
B = [3 4; 6 7]
Find A+B, A*B, A.*B, A/B, A^2, A./B, A.^2
4. A = [ ‘last two digits of your ID’ 2 3 4;5 6 7 8; 9 10 11 12; 13 14 15 16] B = [ 2
3 4 5;6 7 8 9; 10 11 12 13; 14 15 16 17]
C = [ 1 2 3; 4 5 6; 7 8 ‘last digit of your ID’]
(i) Compute AB and BA
(ii) Compute AC. Why do you get an error message?
(iii) Find the transpose of C. Then perform the multiplication of C with it’s transpose
matrix.