FAMILIARIZATION OF THE COMPUTING TOOL
OBJECTIVE
· To familiarize with the
scientific computing tool
LEARNING
OUTCOMES
· After
the completion of this experiment students will be able to compile and run a
MATLAB® code.
· Execute
small scripts using if, for and while statements
SOFTWARE
USED:
MATLAB® R2017a
THEORY
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. This experiment gives you a gentle introduction of MATLAB
programming language. It is designed to give students fluency in MATLAB
programming language. MATLAB (matrix
laboratory) is a fourth-generation high-level programming language and
interactive environment for numerical computation, visualization and
programming.
It allows matrix manipulations, plotting of functions and
data, implementation of algorithms, creation of user interfaces, interfacing
with programs written in other languages, including C, C++, Java, and FORTRAN,
analyze data, develop algorithms and create models and applications.
It has numerous built-in commands and math functions that
help you in mathematical calculations, generating plots, and performing
numerical methods.
MATLAB's Power of
Computational Mathematics
MATLAB is used in every facet of computational mathematics.
Following are some commonly used mathematical calculations where it is used
most commonly.
- Dealing
with Matrices and Arrays
- 2-D
and 3-D Plotting and graphics
- Linear
Algebra
- Algebraic
Equations
- Non-linear
Functions
- Statistics
- Data
Analysis
- Calculus
and Differential Equations
- Numerical
Calculations
- Integration
- Transforms
- Curve
Fitting
- Various
other special functions
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.
Uses of MATLAB
MATLAB is widely used as a computational tool in science
and engineering encompassing the fields of physics, chemistry, math and all
engineering streams. It is used in a range of applications including
- Signal
Processing and Communications
- Image
and Video Processing
- Control
Systems
- Test
and Measurement
- Computational
Finance
- Computational
Biology
LAB
EXERCISE
(a) Needs and requirements in
scientific computing
Scientific Computing is
the collection of tools, techniques, and theories required to solve on a
computer mathematical models of problems in Science and Engineering.
A majority of these tools, techniques, and theories originally developed
in Mathematics, many of
them having their genesis long before the advent of electronic computers. This
set of mathematical theories and techniques is called Numerical Analysis (or Numerical Mathematics) and constitutes
a major part of scientific computing.
The development
of the electronic computer, however, signaled a new era in the approach to the
solution of scientific problems. Many of the numerical methods that had been
developed for the purpose of hand calculation (including the use of desk
calculators for the actual arithmetic) had to be revised and sometimes
abandoned. Many of these considerations – programming languages, operating
systems, management of large quantities of data, correctness of programs – were
subsumed under the new discipline of Computer Science, on which scientific computing now depends
heavily. But mathematics itself continues to play a major role in scientific
computing: it provides the language of the mathematical models that are to be
solved and information about the suitability of a model. In summary, then,
scientific computing draws on mathematics and computer science to develop the
best way to use computer systems to solve problems from science and
engineering.
(b)
Familiarization of MATLAB
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.
I. Type the following in
the command window and write down the results
(1) x=3
(2) x=7*8;
y=x*1.28
(3) clear all
(4)
initial_velocity = 0;
acceleration = 9.8;
time = 20;
final_velocity = initial_velocity + acceleration *
time
(5)
x = sqrt(16)
(6) clc
(7) help sqrt
(8) disp a
(9) a=2;
disp(a)
(c) Familiarization of data
types in the language used
MATLAB does not require
any type declaration or dimension statements. Whenever MATLAB encounters a new
variable name, it creates the variable and allocates appropriate memory space.
Data Types Available in MATLAB
MATLAB provides 15
fundamental data types. Every data type stores data that is in the form of a
matrix or array. The size of this matrix or array is a minimum of 0-by-0 and
this can grow up to a matrix or array of any size.
Sr.No. |
Data Type & Description |
1 |
int8 8-bit signed integer |
2 |
uint8 8-bit unsigned integer |
3 |
int16 16-bit signed integer |
4 |
uint16 16-bit unsigned integer |
5 |
int32 32-bit signed integer |
6 |
uint32 32-bit unsigned integer |
7 |
int64 64-bit signed integer |
8 |
uint64 64-bit unsigned integer |
9 |
single single precision numerical data |
10 |
double double precision numerical data |
11 |
logical logical values of 1 or 0, represent true and
false respectively |
12 |
char character data (strings are stored as vector of
characters) |
13 |
cell array array of indexed cells, each capable of storing
an array of a different dimension and data type |
14 |
structure C-like structures, each structure having named
fields capable of storing an array of a different dimension and data type |
15 |
function handle pointer to a function |
16 |
user classes objects constructed from a user-defined class |
17 |
java classes objects constructed from a Java class |
(d) Familiarization of
the syntax of while, for, if statements.
II
(1) Execute a script (m file) to check
whether a number is divisible by 3
PROCEDURE
1.
Open MATLAB®
2.
Open new M-file
3.
Type the program
4.
Save in current directory
5.
Compile and Run the
program
6.
For the output see
command window\ Figure window
PROGRAM
clc;
clear all;
close all;
a=input('enter value of a');
if mod(a,3)==0
disp ('divisible
by 3')
else
disp ('not
divisible by 3')
end
INPUT
enter value of a 12
OUTPUT
divisible by 3
(2)
Execute a script (m file) to check whether a number is prime or not using while
loop
PROGRAM
clc;
clear all;
close all;
n=input('enter number');
i=2;
while i<=n/2
if mod(n,i)==0
flag=1;
break;
end
i=i+1;
end
if n==1
disp('neither prime nor composite');
else
if flag==1
disp('not
prime');
else
disp('prime');
end
end
(3) Execute a script (m file) to check whether a number is prime or not using for loop
PROGRAM
clc;
clear all;
close all;
n=input('enter number');
for i=2:n/2
if mod(n,i)==0
flag=1;
break;
end
end
if n==1
disp('neither prime nor composite')
else
if flag==1
disp('not
prime')
else
disp('prime')
end
end
INPUT
enter number 12
OUTPUT
not prime
(e)
Basic syntax and execution of small scripts.
III 1. Execute a script (m file) to create an
array whose starting value is 100 and ends at 50 with a decrement of 7
PROGRAM
clc;
clear all;
close all;
a=[100:-7:50];
disp(a)
OUTPUT
[100 93 86
79 72 65
58 51 ]
2.
Execute a script (m file) to add two matrices
PROGRAM
clc;
clear all;
close all;
a=[1 3;4 5;7 9];
b=[3 4;4 3;5 6];
c=a+b;
disp (c)
OUTPUT
4
7
8
8
12
15
3.
Execute a script (m file) to find transpose of a matrix
PROGRAM
clc;
clear all;
close all;
a=[1 3;4 5;7 9];
c=a';
disp (c)
OUTPUT
1
4 7
3
5 9
4.
Execute a script (m file) to display the second row of a 3x3 matrix as the
output
PROGRAM
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
a(2,:)
OUTPUT
[4 5
6]
5.
Execute a script (m file) to display the second row third column element of a
3x3 matrix as the output
PROGRAM
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
a(2,3)
OUTPUT
ans
=6
6.
Execute a script (m file) to do element by element multiplication of 2 matrices
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
b=[1 5 2;2 2 3; 1 2 3];
a.*b
OUTPUT
1
15 6
8
10 18
7
16 27
INFERENCE:
Familiarized
with MATLAB which is basically a scientific computing tool based on simulations
Comments
Post a Comment