You are on page 1of 5

Experiment No: 01

Experiment Name: Introduction to MATLAB.


Objectives:
1. To get familiar with the MATLAB working environment.
2. To get familiar with how to declare and process matrices.

Theory:
What is MATLAB?
MATLAB is widely used in all areas of applied mathematics, in education and
research at universities, and in the industry. MATLAB stands for Matrix
Laboratory and the software is built up around vectors and matrices. This makes
the software particularly useful for linear algebra but MATLAB is also a great tool
for solving algebraic and differential equations and for numerical integration.
MATLAB has powerful graphic tools and can produce nice pictures in both 2D and
3D. It is also a programming language, and is one of the easiest programming
languages for writing mathematical programs. MATLAB also has some tool boxes
useful for signal processing, image processing, optimization, etc.

Familiarization of MATLAB interface?


MATLAB is a powerful programming and numerical computing environment that
provides an intuitive interface for performing various tasks. The MATLAB
interface is designed to facilitate data analysis, algorithm development, and
visualization. It consists of multiple windows and panels, such as the Command
Window, Editor, and Workspace, which allow users to interact with the software.
The Command Window serves as a command-line interface, where MATLAB
commands can be executed and results are displayed. The Editor provides a text-
based environment for writing and editing MATLAB code. The Workspace
displays variables and their values, aiding in debugging and analysis. Overall,
MATLAB's interface offers a user-friendly and efficient environment for working
with numerical data and implementing algorithms.
What is M file MATLAB?

An m-file, or script file, is a simple text file where you can place MATLAB
commands. When the file is run, MATLAB reads the commands and executes them
exactly as it would if you had typed each command sequentially at the MATLAB
prompt. All m-file names must end with the extension.
What is MATLAB Simulink?

Simulink provides a graphical editor, customizable block libraries, and solvers for
modeling and simulating dynamic systems. It is integrated with MATLAB®,
enabling you to incorporate MATLAB algorithms into models and export
simulation results to MATLAB for further analysis.

Lab Work:
Code Output
Random 3*3 order matrices: B=
B=magic (3) 8 1 6
3 5 7
4 9 2
Colon generates number sequence: 1. K =
1. K=(7:11) 7 8 9 10 11
2. P =
2. P=(-1:1) -1 0 1
Specify step size with second colon: 3. H =
3. H= (4:2:12) 4 6 8 10 12
4. I =
4. I= (5:-2:1) 4 3 1
5. Y =
5. Y= (5:-0.7:3) 5.0000 4.3000 3.6000

Select rows, columns and submatrices of B: 6. W =


6. W=B(2,:) 3 5 7
7. U =
7. U=B(:,3) 6
7
8. R=B(1:3,2:3) 2
8. R =
1 6
5 7
9 2

Matrices Can also be accessed as a 9. O =


1dimensional vector: 5 9 6 7 2
9. O=B(5:end) 10. E =
10. E=B(2:2:9) 3 1 9 7
11. Q=size(B) 11. Q =
3 3

New Matrices Operation:


12. S=[3 9;5 2] 12. S =
3 9
13. N=[B(end,:);B(:,2)'] 5 2
13. N =
3 9 2
1 5 9

Code Output
14. A=[zeros(1,3);B(3,:)] 14. A =
0 0 0
4 9 2
Mask Matrix elements: 15. S =
15. S=find(B>5) 1
6
7
8
16. T =
16. T=find(B<=2)
4
9
17. B =
17. B(find(B>5))=0 0 1 0
3 5 0
4 0 2
perators on scalars and matrices: 18. X =
18. X=[4 7;2 8]*[2 9]' 71
76
19. U=[3 7 9].*[3 7 1] 19. U =
9 49 9

Inner and outer vector product: 20. R =


20. R=[7 5 9]*[2 8 5]' 99

21. P=[2 7 5]'*[3 1 7] 21. P =


6 2 14
21 7 49
15 5 35

Plotting:
22. x=0:15; y=0.7-0.7*cos(2*pi*x/15);
stem(x,y);
title('15-point stem graph');

Code Output
Plotting:
23. x=0:0.2:15; y=exp(x *(j-1/3));
plot(x,real(y),x,imag(y)); grid;
legend('real','imaginary');

2D Plotting:
24. x1=-10:0.2:30; y1=-
10:0.2:30;
[x,y]=meshgrid(x1,y1);
p=sqrt(x.^2+y.^2);
q=sin(p)./p; q(find(p==0))=1;
plot3(x,y,q);
grid on;

Conclusion:
In conclusion, Matlab is a important software in our daily life. It is important for an engineer or a
mathematics students. In this lab we got a big knowledge about Matlab software. It will help
my daily life work doing easier. Everyone should know about Matlab software and its
important. It is help to our life easier. Introduction to MATLAB has provided a glimpse into the
powerful capabilities of the software. We explored its versatility in handling numerical
computations, data analysis, and visualization. MATLAB's user-friendly interface, extensive
library of functions, and programming capabilities make it an invaluable tool for engineers,
scientists, and researchers. With further practice and exploration, users can harness MATLAB's
full potential for their specific needs.

You might also like