0% found this document useful (0 votes)
65 views8 pages

Experiment 1: (Done By: Mohammed Adel)

The document discusses various operations in MATLAB including: 1) Assigning values, defining variables, and using basic commands like Lookfor, Clear, Help, etc. 2) Performing addition, subtraction, and multiplication on matrices. As well as finding the inverse, transpose, and determinant of matrices. 3) Plotting graphs by defining x and y variables and using commands like plot, xlabel, ylabel, title, grid.

Uploaded by

Adel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views8 pages

Experiment 1: (Done By: Mohammed Adel)

The document discusses various operations in MATLAB including: 1) Assigning values, defining variables, and using basic commands like Lookfor, Clear, Help, etc. 2) Performing addition, subtraction, and multiplication on matrices. As well as finding the inverse, transpose, and determinant of matrices. 3) Plotting graphs by defining x and y variables and using commands like plot, xlabel, ylabel, title, grid.

Uploaded by

Adel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Experiment 1 (Done by: Mohammed Adel)

Introduction to Matlab
• Assigning values in Matlab

1. X=10
2. X=2+5
3. X=7-3
4. X=3*2
5. X=8/2
6. X=sqrt (49)
7. X=2. ^5
8. X=2; y=4; z=y-x

• Some important commands

1. Lookfor – Searches help entries for a keyword


2. Clear – Removes variables from the window
3. CLC – Clears the command window
4. Exist – Checks for existence of a file or a variable
5. Global – Declares a variable to the global
6. Help – Searches for a help topic
7. Quit – Stops Matlab
8. Who – Lists current variables
9. Whos – Lists current variables (long display)

• Different data formats

1. Default format – 4 digits of precision


2. Short format – 2 digits of precision
3. Long format – 4 digits of precision
Experiment 2
• Addition Operation

noofstudents= 6000;
teachingstaff = 150;
nonteachingstaff = 20;

total=noofstudents+teachingstaff+nonteachingstaff;

disp(total);

• Matrix Operations

1. a = [1 2 3; 4 5 6; 7 8 9];
2. b = [7 5 6; 2 0 8; 5 7 1];
3. a (2,5)
4. a (:,1:3)
5. a (2:3,:)
6. a (3,:)
7. a (3,:) = []
8. a (:,3) = []
9. a = [1 2 3; 4 5 6; 7 8 9];
10. b = [7 5 6; 2 0 8; 5 7 1];
11. c=a+b
12. d=a-b
13. inv(a)
14. a = [10 12 23; 14 8 6; 27 8 9];
15. b = a’
16. B = [2 1 3; 5 0 -2; 2 3 -1];
17. Prod = a*b
18. a = [1 2 3; 2 3 4; 1 2 5];
19. det(a)
• To delete a row

1. Input

a = [ 1 2 3; 2 5 6; 7 8 9];
display(a);
a(3,:) = []

2. output

a= 1 2 3
2 5 6
7 8 9

a= 1 2 3
2 5 6

• To delete a column

1. Input
a = [ 1 2 3; 2 5 6; 7 8 9];
display(a);
a(:,3) = []

2. output

a=1 2 3
2 5 6
7 8 9

a= 1 2
2 5
7 8
• To add or subtract the matrices

1. Input

a = [ 1 2 3; 2 3 4; 1 2 5];
b = [ 1 1 1; 1 1 1; 1 1 1];
c = a +b
d=a–b

2. Output

c =2 3 4
3 4 5
2 3 6

d =0 1 2
1 2 3
0 1 4

• To find the product of matrices

1. Input

a = [ 1 2 3; 2 3 4; 1 2 5];
b = [ 1 1 1; 1 1 1; 1 1 1];
prod = a * b
2. Output

prod =6 6 6
9 9 9
8 8 8

• To find the inverse of a matrix

1. Input

a= [ 1 2 3 ; 2 3 4; 1 2 5]
inv(a)
2. Output

-3.5000 2.0000 0.5000


3.0000 -1.0000 -1.0000
-0.5000 0 0.5000

• To find the transpose of a matrix

1. Input
a = [ 1 2 3 ; 2 3 4; 1 2 5]
b = a'

2. Output
1 2 1
2 3 2
3 4 5
• To find the determinant of a matrix

1. Input
a= [ 1 2 3 ; 2 3 4; 1 2 5];
det(a)

2. Output
ans = -2

• Plotting graphs

1)
Input
x = [0:5:100];
y = x;
plot(x, y)

Output
2) Input
X=[1 2 3 4 5];
x = [-100:20:100];
y = x.^2;
plot(x, y)

Output

3)

Input
x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('sin(x)'), title('sin(x) graph'), grid on, axis
equal

Output

You might also like