Basics of Matrix Laboratory
Published: 2024-02-13 11:53:04

My name is Sushma B R, and I am working as Software Engineer at Luxoft India. In this article I will be providing the detailed information towards Matrix Laboratory. Luxoft has provided me with multiple opportunity to work on various projects MATLAB is one among them.

**Introduction:-**
Matrix Laboratory (MATLAB) is a high performance language that is used for technical computing. It changed into advanced by means of Cleve Molar of the employer MathWorks.Inc in the year 1984. It is written in C, C++, Java languages. It permits matrix manipulations, plotting of capabilities, implementation of algorithms and introduction of consumer interfaces.

**Getting started with MATLAB:**
It is both a programming language as well as a programming surroundings. It permits the computation of statements within the command window itself.

- 
**Command Window:**
In this window one should kind and right away execute the statements, as it requires short prototyping. These statements cannot be saved. Thus, that is may be used for small, without problems executable packages.

- 
**Editor (Script):**
In this window one can execute larger programs with the multiple statements, and complex functions. These can be saved and are done with the file extension ‘.m ‘

- 
**Workspace:**
In this window the values of the variables that are created inside the path of the program (in the editor) are displayed.
This window shows the precise area(course) of this system record being created.

MATLAB Library comes in a set of many in-built capabilities. These features primarily carry out mathematical operations like sine, cosine and tangent. They carry out more complicated capabilities too like finding the inverse and determinant of a matrix, pass product and dot product.
Although MATLAB is encoded in C, C++ and Java, it is a lot less difficult to put in force than those three languages. For instance, not like the alternative 3, no header files want to be initialised in the beginning of the document and for putting forward a variable, the information kind need not be furnished. It offers an less difficult alternative for vector operations. They can be performed using one command in place of multiple statements in a for or while loop.

**Some basic functions in the MATLAB and uses of them are listed below:**

- 
disp() - The values or the text printed within single quotes is displayed on the output screen.

- 
clear -	To clear all variables.

- 
close all - To close all graphics window.

- 
clc -	To clear the command window.

- 
exp(x)	- To compute the exponential value of x to the base e.

- 
abs(x) - To compute absolute value of x.

- 
sqrt(x) - To compute the square root of x.

- 
log(x)	- To compute the logarithmic value of x to the base e.

- 
log10(x) - To compute logarithmic value of x to the base 10.

- 
rem(x, y) - To compute the remainder of x/y.

- 
sin(x) - To compute the sine of x.

- 
cos(x) - To compute the cosine of x.

- 
tan(x) - To compute the tangent of x.

- 
atan2(x, y) - To compute the arctangent or inverse of y/x.



**Writing a MATLAB program:**

**1. Using Command Window:**
Only one announcement can be typed and executed at a time. It executes the declaration whilst the input key is pressed. This is in most cases used for easy calculations.
Note: ans is default variable created in MATLAB that stores the output of the given computation.

**2. Using Editor:**
Multiple lines of code can be written right here and most effective after pressing the run button (or F5) will the code be performed. It is usually a great exercise to write clc, clear and close all within the beginning of the program.
Note: Statements ending with a semicolon will not be displayed in the command window, however, their values will be displayed in the workspace.
Any of the statement followed by symbol % in MATLAB is considered as a comment.

**3. Vector Operations:**
Operations which includes addition, subtraction, multiplication and department may be accomplished the usage of a single command as opposed to a couple of loops.

We also can extract separate rows and columns by using the usage of the colon(:) operator. Consider a matrix A of size 3X3. The following commands may be used to extract rows and columns from Matrix A.

- 
A(:, n)	- To extract the elements of all rows in column n of the matrix.

- 
A(m, : ) - To extract the elements of all columns in row m of the matrix.

- 
A(:, m:n) - To extract the elements of all rows between columns m and n of the matrix.

- 
A(m:n, : ) - To extract elements of all columns between rows m and n of the matrix.

- 
A(p:q, m:n) - To extract elements of rows between p and q and columns between m and n of the matrix.

- 
A(m, n) - To extract elements of row m and column n.


**Plotting in MATLAB:**

The MATLAB photos machine consists of high-level commands for 2-dimensional and three-dimensional records visualization, image processing, animation, and presentation pix. It also includes the low-level commands that permits to completely personalize the appearance of picture and as well as to build whole Graphical User Interfaces.

Given below is code for plotting a Parabola:
x = 0:0.5:10;

%Indicates that the x varies from 0 to 10 with the intervals of 0.5
y = x>^2;

%Indicates that the square of each element in the x is stored in the y
plot(x, y)%plotting x and y
xlabel(X)%naming x axis as x
ylabel(Y)%naming y axis as y
title('Graph of y=x^2')%Title of the graph 

This code will give the following graph:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xhflgnruvam6ms97gkt.png)

You can trade the color of the graph with the aid of including some other statement inside the plot command. For example, plot(x, y, ‘r’) will give the graph line in crimson.

Graphs together with sine, cosine and other trigonometric functions’ curve can also be plotted. The code for sine curve is given underneath:

x = 0:pi/100:2*pi;
y = sin(x); 

plot(x, y, ‘g’)% Will give the graph line in green.


In conclusion, MATLAB is a totally user pleasant language and it is also easy to recognize. It’s library is prepared with features that help us perform loads of mathematical functions.