Matlab Lecture1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

MATLAB

Prof. Rawya Rizk


[email protected]

Lecture 1
Matlab Desktop
Arithmetic Operations

Exponentiation A^B
Multiplication A*B
Division A/B
Addition A+B
Subtraction A-B
Arithmetic Operations
Calculate
Average = 1+ 2 + 3 / 3

Average = (1+ 2+ 3)/ 3

V1=3*(2^3+2)/2-2

V2=3*(2^3+2)/ (2-2)
Constants & Variables

 A variable is a storage for a value that


can change during code execution

 A constant is a storage for a value that


does not change during code execution.
Can be changed manually
Errors
Matlab Fundamentals: Comments

To enter a comment sentence, we use % in the beginning


of the sentence:

Ex:
% this is a comment sentences
Matlab Fundamentals: Vectors
• Row Vector: (Matrix with one row)
Ex:
% let's create a simple row vector with 9 elements called
'a'.

a = [1 2 3 4 6 4 3 4 5]

• Column Vector: (Matrix with one column)


Ex:
% let's create a simple column vector with 5 elements
called 'b'.

b= [9;9;8;6;9]
Matlab Fundamentals: Matrices
% creating a matrix is as easy as making a
vector, using semicolons (;) to separate the rows
of a matrix.

A = [1 2 0; 2 5 -1; 4 10 -1]
Matrix Arithmetic Operations
•Transpose
Ex:
% we can easily find the transpose of the matrix 'A'.
B = A'
B =
1 2 4
2 5 10
0 -1 -1
Matrix Arithmetic Operations

Note that:
Matrix Arithmetic Operations
•Multiplication:

Now let's multiplies these two matrices together.


Note that MATLAB doesn't require you to deal with matrices as a
collection of numbers. MATLAB knows when you are dealing with
matrices and adjusts your calculations accordingly.

C = A * B

% Instead of doing a matrix multiply, we can multiply the


corresponding elements of two matrices or vectors using the .*
operator.

C = A .* B
Matrix Arithmetic Operations
>> x=[6 6; 8 8] Note that:
x=

6 6
8 8

>> y= [3 3; 2 2]

y=

3 3
2 2

• Right Division:

>> x./y

ans =

2 2
4 4

• Left Division:

>> x.\y

ans =

0.5000 0.5000
0.2500 0.2500
Matrix Arithmetic Operations
• Power:

R= [7 8 4];
S= [2 4 5];
Q=R.^S
Q =
49 4096 1024
Matrix and Vector Operations

You might also like