top of page
Writer's pictureThe Tech Platform

Introduction to MATLAB

Updated: Jul 13, 2022



MATLAB - Matrix Laboratory

MATLAB is a programming language developed by MathWorks. It started out as a matrix programming language where linear algebra programming was simple. It can be run both under interactive sessions and as a batch job. It is designed to give students fluency in MATLAB programming language. Problem-based MATLAB examples have been given in simple and easy way to make your learning fast and effective. The basic functions of Matlab are plotting of functions and data, the creation of user interfaces, matrix manipulations. It also provides support for interfacing with other programming languages in C, C++, Fortran, and Java. Besides, it is also used to analyze data, create models and applications, and also develop algorithms. Matlab also has a very good scope in the automotive domain using Rapid control Prototyping or RCP used extensively in medical, automotive, and aerospace domains.


MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include:

  • Math and computation

  • Algorithm development

  • Modeling, simulation, and prototyping

  • Data analysis, exploration, and visualization

  • Scientific and engineering graphics

  • Application development, including Graphical User Interface building


MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar noninteractive language such as C or Fortran.


History:

MATLAB was invented by mathematician and computer programmer Cleve Moler. The idea for MATLAB was based on his 1960s PhD thesis. Moler became a math professor at the University of New Mexico and started developing MATLAB for his students as a hobby. He developed MATLAB's initial linear algebra programming in 1967 with his one-time thesis advisor, George Forsythe. This was followed by Fortran code for linear equations in 1971.


The first early version of MATLAB was completed in the late 1970s. The software was disclosed to the public for the first time in February 1979 at the Naval Postgraduate School in California. Early versions of MATLAB were simple matrix calculators with 71 pre-built functions. At the time, MATLAB was distributed for free to universities. Moler would leave copies at universities he visited and the software developed a strong following in the math departments of university campuses. :5


In the 1980s, Cleve Moler met John N. Little. They decided to reprogram MATLAB in C and market it for the IBM desktops that were replacing mainframe computers at the time. John Little and programmer Steve Bangert re-programmed MATLAB in C, created the MATLAB programming language, and developed features for toolboxes



Syntax:


Type a valid expression, for example,

5 + 5

And press ENTER


When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −

ans = 10

Let us take up few more examples −

3 ^ 2	       % 3 raised to the power of 2

When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −

ans = 9

Another example,

sin(pi /2)	  % sine of angle 90o

When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −

ans = 1

Another example,

7/0		      % Divide by zero

When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −

ans = Inf
warning: division by zero

Another example,

732 * 20.3	

When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −

ans =  1.4860e+04

MATLAB provides some special expressions for some mathematical symbols, like pi for π, Inf for ∞, i (and j) for √-1 etc. Nan stands for 'not a number'.


Commonly used Operators and Special Characters

Operator Purpose

1. + Plus; addition operator.

2. - Minus; subtraction operator.

3. * Scalar and matrix multiplication operator.

4. .* Array multiplication operator.

5. ^ Scalar and matrix exponentiation operator.

6. .^ Array exponentiation operator.

7. \ Left-division operator.

8. / Right-division operator.

9. .\ Array left-division operator.

10. ./ Array right-division operator.

11. : Colon; generates regularly spaced elements and represents an entire row or column.

12. ( ) Parentheses; encloses function arguments and array indices; overrides precedence.

13. [ ] Brackets; enclosures array elements.

14. . Decimal point.Ellipsis; line-continuation operator

15. , Comma; separates statements and elements in a row

16. ; Semicolon; separates columns and suppresses display.

17. % Percent sign; designates a comment and specifies formatting

18. ._ Quote sign and transpose operator.

19. ._ Nonconjugated transpose operator.

20. = Assignment operator.



Special Variables and Constants

MATLAB supports the following special variables and constants −

Name Meaning

1. ans Most recent answer.

2. eps Accuracy of floating-point precision.

3. i,j The imaginary unit √-1.

4. Inf Infinity.

5. NaN Undefined numerical result (not a number).

6. pi The number π



Installation:

Setting up MATLAB environment is a matter of few clicks. The installer can be downloaded from here.

MathWorks provides the licensed product, a trial version and a student version as well. You need to log into the site and wait a little for their approval.


After downloading the installer the software can be installed through few clicks.





MATLAB Environment

MATLAB development IDE can be launched from the icon created on the desktop. The main working window in MATLAB is called the desktop. When MATLAB is started, the desktop appears in its default layout −



The desktop has the following panels −

  • Current Folder − This panel allows you to access the project folders and files.


  • Command Window − This is the main area where commands can be entered at the command line. It is indicated by the command prompt (>>).


  • Workspace − The workspace shows all the variables created and/or imported from files.


  • Command History − This panel shows or return commands that are entered at the command line.





MATLAB Components:

Matlab provides a lot of functionalities that can help in computational mathematics. Below are the most common functions and mathematical calculations used in Matlab –


Dealing with Matrices and Arrays:

Matrices and arrays are the fundamental representation of information and data in MATLAB. You can create common arrays and grids, combine existing arrays, manipulate an array's shape and content, and use indexing to access array elements. For an overview of matrix and array manipulation, watch Working with Arrays.


2-D and 3-D Plotting and graphics:

  1. 2D Plotting in MATLAB: plot( X , Y ) creates a 2-D line plot of the data in Y versus the corresponding values in X . To plot a set of coordinates connected by line segments, specify X and Y as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X or Y as a matrix

  2. 3D Plotting in MATLAB: 3D scatter plots are used to plot data points on three axes in the attempt to show the relationship between three variables. Each row in the data table is represented by a marker whose position depends on its values in the columns set on the X, Y, and Z axes.

  3. Graphics in MATLAB: Graphics objects are the components used by MATLAB® to create visualizations of data. Each object plays a specific role in the graphics display. For example, a line plot consists of a figure object, an axes object, and a chart line object. You can customize graphics objects by setting their properties.


Linear Algebra:

Linear algebra functions in MATLAB provide fast, numerically robust matrix calculations. Capabilities include a variety of matrix factorizations, linear equation solving, computation of eigenvalues or singular values, and more. For an introduction, see Matrices in the MATLAB Environment.


Algebraic Equations:

Algebraic Equation, statement of the equality of two expressions formulated by applying to a set of variables the algebraic operations, namely, addition, subtraction, multiplication, division, raising to a power, and extraction of a root.


Non-linear Functions:

Non-linear means the graph is not a straight line. The graph of a non-linear function is a curved line. A curved line is a line whose direction constantly changes.


Statistics and Machine Learning Toolbox:

Statistics and Machine Learning Toolbox™ provides tools for accessing, preprocessing, and visualizing data; extracting features; training and optimizing models; and preparing models for deployment. The typical workflow begins with accessing, cleaning, and preprocessing your data in preparation for extracting features.


Data Analysis:

Engineers and scientists use MATLAB® to organize, clean, and analyze complex data sets from diverse fields such as climatology, predictive maintenance, medical research, and finance. MATLAB provides: Datatypes and preprocessing capabilities designed for engineering and scientific data.


Calculus and Differential Equations:

Allow your students to effortlessly switch among visual, numerical, and algebraic representations of calculus concepts. Shift emphasis from manipulative skills to fundamental calculus ideas. Improve students' engagement and concept retention by exploring more realistic problems earlier.


Numerical Calculations:

Numerical Calculations focuses on MATLAB capabilities to give readers numerical solutions to problems they are likely to encounter in their professional or scholastic life. It introduces them to the MATLAB language with practical hands-on instructions and results, allowing them to quickly achieve their goals.


Integration:

Numerical integration functions can approximate the value of an integral whether or not the functional expression is known: When you know how to evaluate the function, you can use integral to calculate integrals with specified bounds.


Curve Fitting:

Curve Fitting Toolbox provides an app and functions for fitting curves and surfaces to data. The toolbox lets you perform exploratory data analysis, preprocess and post-process data, compare candidate models, and remove outliers.


Features of MATLAB:

Following are the basic features of MATLAB −

  • It is a high-level language for numerical computation, visualization and application development.

  • It also provides an interactive environment for iterative exploration, design and problem solving.

  • It provides vast library of mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, numerical integration and solving ordinary differential equations.

  • It provides built-in graphics for visualizing data and tools for creating custom plots.

  • MATLAB's programming interface gives development tools for improving code quality maintainability and maximizing performance.

  • It provides tools for building applications with custom graphical interfaces.

  • It provides functions for integrating MATLAB based algorithms with external applications and languages such as C, Java, .NET and Microsoft Excel.


Application of MATLAB:

Matlab is widely used in the industry as a tool for mathematical computation and different streams of studies like physics chemistry, engineering, mathematics, Etc. The various applications involving Matlab are below –

  1. Computational Finance

  2. Control systems

  3. Signal Processing and communication

  4. Test and Measurement

  5. Image and video processing

  6. Computational biology


Advantages of MATLAB:

  1. Matlab is a compiler-independent tool and doesn’t require any compiler to execute like as required in C, C ++. Codes are written in sentences and executed one by one.

  2. Being compiler-independent makes Matlab more efficient and productive.

  3. Matlab is a fourth-generation high-level language.

  4. Matlab coder is used to converting the code that is written in Matlab to Java, Python, C++, .NET, etc., making the Matlab language more versatile.

  5. Different languages can be used to implement scientific theories, and after building the library files or .dll files, those can be directly implemented in Matlab using other languages.

  6. The inbuilt rich library of Matlab contains a library of the neural network, power system, communication, fuzzy logic, hydraulics, Simulink, electromagnetics, electrics, etc. Thus, using this reach library, it is always easy to develop and implement any scientific simulation. These tools can be controlled by using built-in codes so that any manual intervention of the control can be avoided in the model.

  7. Complex mathematical operations like matrix multiplication and addition can be easily accomplished in a single code by using Matlab.

  8. Matlab also supports loops by using the length of code same or even shorter as compared to C or C++ in a much convenient way.

  9. Matlab also supports the writing of user-defined functions, which are extremely easy to implement and also can be stored in separate files for future use. This potentially saves a lot of time writing the same code which is needed for different operations and functions in regular use.

  10. Matlab allows the import and export of data to or from a text or excels file using a single command which is very useful for analysis of previously recorded data. Matlab allows storage of data in excel files or .mat files.


Disadvantages of MATLAB:

  1. Cross-compiling of Matlab code to other languages is very difficult and requires deep Matlab knowledge to deal with errors produced.

  2. Matlab is used mainly for scientific research and is not suitable for development activities that are user-specific.

  3. Matlab is an interpreted language; thus, it can be very slow.

  4. Poor programming practices can contribute to making Matlab unacceptably slow.

  5. Matlab is more expensive. The license is very costly, and users need to buy each and every module and need to pay for the same.

  6. Matlab is not known to create application deployment for installation like the task done by others which includes the setting of files another executable that copies during installation.



Resource: Mathworks.com


The Tech Platform

0 comments

Comments


bottom of page