Professional Documents
Culture Documents
Experiment 1: (Done By: Mohammed Adel)
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
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
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
1. Input
a= [ 1 2 3 ; 2 3 4; 1 2 5]
inv(a)
2. Output
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