You are on page 1of 14

CHAPTER 2

1
Programming Languages
A programming language is a set of commands,
instructions, and other syntax used to create a computer
program (or software).

 Programming languages can be grouped into three


main categories
• Machine languages
• Assembly languages
• High-level languages
2
Types of Programming Languages
1) Machine Languages: Machine language is the
computer’s native language, which is used to directly
control the CPU. It consists of a set of built-in primitive
instructions in the form of binary code (0s and 1s).
• Machine languages are defined by hardware design
• Disadvantages
 Programming in machine language is tedious
 Codes written in machine language are difficult to read
and modify 3
2) Assembly Languages: Assembly language uses short
descriptive words called mnemonics to represent the
machine language instructions.
• Each assembly language instruction corresponds to an
instruction in machine language
• It is easier to code in assembly than machine language
• Disadvantages
 It is machine dependent
 Still tedious to write code in assembly language
 Requires understanding of how the CPU works 4
3) High-Level Languages: These are programming
languages that allow computer programs to be written
using natural human languages.
• Advantages over low-level languages
 They are English-like and easy to learn and use
 They are platform-independent
 Do not require knowledge of the CPU architecture
• High-level languages can be divided into two types:
Compiled and Interpreted programming languages
5
Compiled and Interpreted High-Level Languages
• A program written in a high-level language is called a source
program or source code
• A compiled language uses a tool known as a compiler to convert
the source code into machine code
 A compiler translates the entire source code into a machine-
code file
• An interpreted language uses an interpreter to convert the
source code into machine code
 An interpreter reads one statement from the source code,
translates it to machine code and then executes it right away
6
Examples of High-Level Languages
Language Uses a Compiler Uses an Interpreter
Pascal 
FORTRAN 
Visual Basic 
C 
C++ 
C# 
Java 
MATLAB 
Python 
Perl 
Julia 
Ruby  7
MATLAB Programming
• MATLAB stands for MATrix LABoratory
• MATLAB was invented by Cleve Moler in the late 1970s
• MATLAB is written in C.
• MATLAB works as an interpreter
• MATLAB codes run slower than codes written in C/C++ and
FORTRAN
• Uses of MATLAB
 For Data Analysis
 For developing algorithms
 For creating models and applications 8
MATLAB Programming
• MATLAB is a multi-disciplinary tool
• Can be used in Numerical Computation Applications
• Has over 90 Toolboxes in multiple fields
 Mathematics (Symbolic Math, Statistics, Curve Fitting, etc)
 Communications & Signal Processing
 Machine Vision (Image Processing, Computer Vision)
 Statistics and Regression Analysis
 Computational Finance
 Instrument Control, Vehicle Dynamics, Aerospace, etc
9
MATLAB 2019 User Interface
Command
Window

Current
Folder

Workspace

10
Some Basic MATLAB Commands
who
Lists the names of the variables defined by the user

whos
Lists detailed information about the variables defined by
the user

clc
Clears the command window
11
Some Basic MATLAB Commands
clear
Deletes all the variables from the MATLAB workspace

clear <variable name>


Deletes a certain variable
clearvars
Same as clear but more stable
beep
Produce a beep sound 12
Some Basic MATLAB Commands
date
Shows the current system date

disp (<variable name>)


Displays the value of the variable
disp (<string constant>)
Displays the string constant
ans
Automatically created variable assigned to a result 13
Interactive MATLAB Programming
• MATLAB works primarily (almost exclusively) with matrices
• MATLAB has built-in mathematical functions that are optimized
to handle matrix operations
• MATLAB can handle up to 13-Dimensional matrices

What is a Matrix?
• A matrix is a one- or multi-dimensional array of elements
• All data in MATLAB are viewed as matrices
• Thus, a scalar is a matrix with only one row and one column
• A vector contains only one row or one column 14

You might also like