MATLAB
MATLABÂ is a programming and numeric computing platform
Introduction
MATLAB is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.
HISTORY
Started by cleve moler in 1970s
Later jack little,steve bangert and cleve moler fonded Mathworks in 1984 and rewrite MATLAB IN C language
Table of contents
02
Capabilities
Operators
Uses
Practical exercises
01
04
03
MATLAB's built-in functions provide excellent tools for linear algebra computations
An operator is a symbol that tells the compiler to perform various numerical or logical manipulations
solving engineering and scientific problems
Go through this practical at your own pace and learn about the MATLAB environment in more detail
How it is different from other languages?
Here’s what you’ll find in this Slidesgo template:
What is MATLAB
1.Programming language specially designed for engineers and scientists.
2.MATLAB=MATrix + LABoratory
3.Simulink
Capabilities
01
Datatypes and preprocessing capabilities designed for engineering and scientific data
01
DATA ANALYSIS
Explore, model, and analyze data
02
GRAPHICS
Visualize and explore data
03
PROGRAMMING
Create scripts, functions, and classes
04
APP BUILDING
Create desktop and web apps
05
EXTERNAL LANGUAGE INTERFACE
Use MATLAB with PYTHON , C/C++, Fortran, Java, and other languages
06
HARDWARE
Connect MATLAB to hardware
07
PARALLEL COMPUTING
Perform large-scale computations and parallelize simulations using multicore desktops, GPUs, clusters, and clouds
08
WEB AND DESKTOP DEVELOPMENT
Share your MATLAB
programs
09
MATLAB IN THE CLOUD
Run in cloud environments from MathWorks Cloud to public clouds including AWS and Azure
02
Features
01
WIRELESS COMMUNICATIONS
Create, design, test, and verify wireless communications systems
02
DEEP LEARNING
Data preparation, design, simulation, and deployment for deep neural networks
03
IMAGE PROCESSING &
COMPUTER VISION
Acquire, process, and analyze images and video for algorithm development and system design
04
MACHINE LEARNING
Train models, tune parameters, and deploy to production or the edge
05
PREDICTIVE MAINTENANCE
Develop and deploy
condition monitoring and predictive maintenance software
06
ROBOTICS
Convert your robotics ideas and concepts into autonomous systems that work seamlessly in real-world environments.
07
SIGNAL PROCESSING
Analyze signals and time-series data. Model, design, and simulate signal processing systems.
08
TEST AND MEASUREMENT
Acquire, analyze, and explore data and automate tests
09
CONTROL SYSTEM
Design, test, and implement control systems
03
Operators
Symbol | Role | More Information |
+ | Addition | Plu splus |
+ | Unary plus | uplusuplus |
- | Subtraction | minus |
- | Unary minus | uminus |
.* | Element-wise multiplication | timestimes |
* | Matrix multiplication | mtimes |
./ | Element-wise right division | rdivierdivide |
/ | Matrix right division | emrdivide |
.\ | Element-wise left division | ldivide |
\ | Matrix left division (also known as backslash) | mldiemldivide |
.^ | Element-wise power | Pow rpower |
^ | Matrix power | mpormpower |
.' | Transpose | tranetranspose |
' | Complex conjugate transpose | ctraectranspose |
ARITHMATIC OPERATORS :
Symbol | Role | More Information |
== | Equal to | eqeq |
~= | Not equal to | nene |
> | Greater than | G tgt |
>= | Greater than or equal to | gege |
< | Less than | Lt lt |
<= | Less than or equal to | Le le |
Symbol | Role | More Information |
& | Find logical AND | and |
| | Find logical OR | Or or |
&& | Find logical AND (with short-circuiting) | Short –circuit AND |
|| | Find logical OR (with short-circuiting) | Short –circuit OR |
~ | Find logical NOT | notnot |
RELATIONAL OPERATORS :
LOGICAL OPERATORS :
04
Exercises
CALCULATOR
MATLAB as a Calculator. calculator MATLAB can be used as a powerful calculator
SCRIPTS
A script is a file that contains multiple sequential lines of MATLAB commands and function calls
VECTORS
A vector is an enclosed set of elements
LINE PLOTS
Line plots make a connection between those first graphs and the more advanced concepts
MATRICES
A matrix is a two-dimensional array of numbers
LOGICAL
MATLAB represents Boolean data using the logical data type
LOOPS
A loop statement allows us to execute a statement or group of statements multiple times
INTERPOLATION
Interpolation is a technique for adding new data points within a range of a set of known data points
Problem 1
Solution 1
Use Matlab to compute the following expressions.
(((sqrt(5)+1)/2)^10-((sqrt(5)-1)/2)^10)/sqrt(5)
Matlab as a calculator
Â
Scripts
Problem 1
Solution 1
Compute the values of cos x and sin x for x = 0, π/6, π/4, π/3, and π/2. Write a script.
x=[0 pi/6 pi/4 pi/3 pi/2];
cos(x);
sin(x);
Vector
Problem 1
Solution 1
Â
V=[1 3 5 7 -9 10];
W=[3;-7;9;10;12];
a=2*V;
b=W.^2;
c=(V.^2)+(2*V);
Line Plots
Problem 1
Solution 1
Â
t=linspace(0,2*pi);
x=cos(t);y=sin(t);
plot(x,y);
axis equal;
axis([-1.1 1.1 -1.1 1.1]);
ax=gca;
ax.XTick=[-1 -0.5 0 0.5 1];
ax.YTick=[-1 -0.5 0 0.5 1];
xlabel('$x$','Interpreter','latex','FontSize',14);
ylabel('$y$','Interpreter','latex','FontSize',14);
title('Plot of a circle','Interpreter','latex','FontSize',16);
Matrices
Problem 1
Solution 1
Construct the following matrix in Matlab
Â
Evaluate the following expressions using
Matlab.
x) A([1,3],[2,4])
y) A(:,[1,4:6])
z) A([2,3],:)
A=[6 9 12 15 18 21;4 4 4 4 4 4;2 1 0 -1 -2 -3;-6 -4 -2 0 2 4];
x=A([1,3],[2,4]);
y=A(:,[1,4:6]);
z=A([2,3],:);
Logicals
Problem 1
Solution 1
Evaluate the following expressions. Check your answer with Matlab.
x) 14>15/3
y) 8/(2<5)*3+(1>9)
z) 2+4+3~=60/4-1
r) 8/2<5*3+1>9
x=14>15/3;
y=8/(2<5)*3+(1>9);
z=2+4+3~=60/4-1;
r=8/2<5*3+1>9;
Loops
Problem 1
Solution 1
1.Write factorial of input number using for loops.
2.write factorial of a input number using while loop.
1.n=input('Enter the number:');
f=1;
for i=1:n
f=f*i;
end
X=['The factorial of ',num2str(n),' is ',num2str(f)];
disp(X);
2.n=input('Enter the number:');
c=n;
fact=n;
while n>1
n=n-1;
fact=fact*n;
end
X=['The factorial of ',num2str(c),' is ',num2str(fact)];
disp(X);
Interpolation
Problem 1
Solution 1
Find the interpolating polynomial that passes through (2,4) , (3,7) , (4,8) , (5,11) , (6,15) hence manipulate the value of y at x = 4.5
x=input('Enter the abscissas:');
y=input('Enter the ordinates:');
p0=input('enter point of approx.:');
n=length(x);
h=x(2)-x(1);
f=zeros(n,n);
f(:,1)=y;
for j=2:n
for i=j:n
f(i,j)=f(i,j-1)-f(i-1,j-1);
end
end
f
C=f(n,n);
for k=n-1:-1:1
p=poly(x(1))/h;
p(2)=p(2)-(k-1);
C=conv(C,p)/k;
m=length(C);
C(m)=C(m)+f(k,k);
end
C
A=polyval(C,p0);
fprintf('Approximate value at given data point is : %.4f\n',A);
Thank You