1. OVERVIEW
• MATLAB (matrix laboratory) is a fourth-generation high-level programming language
and interactive environment for numerical computation, visualization and
programming. MATLAB is developed by MathWorks.
• 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
• Embeded Systemd
• Robotics
• Computer vision
• Image and video Processing
• Control systems
• Test and measurement
• Computational finance
• Computational biology
2. MATLAB ENVIRONMENT
• Naming Variables Variable names consist of a letter followed by any number of letters, digits or
underscore. MATLAB is case-sensitive. Variable names can be of any length; however, MATLAB uses
only first N characters, where N is given by the function namelengthmax.
• Saving Your Work The save command is used for saving all the variables in the workspace, as a file
with .mat extension, in the current directory. For example, save myfile You can reload the file
anytime later using the load command. load myfile
PLOTTING
x = [0:5:100];
y = x;
plot(x, y)
x = [1 2 3 4 5 6 7 8 9 10];
x = [-100:20:100];
y = x.^2;
plot(x, y)
x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)’),
title('Sin(x) Graph'), grid on, axis equal
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-’),
legend('Sin(x)', 'Cos(x)')
MATLAB provides eight basic color options for drawing graphs. The following table shows the
colors and their codes:
x = [-10 : 0.01: 10];
y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')
• Setting Axis Scales
• axis ( [xmin xmax ymin ymax] )
x = [0 : 0.01: 10];
y = exp(-x).* sin(2*x + 3);
plot(x, y),
axis([0 10 -1 1])
x = [0:0.01:5];
y = exp(-1.5*x).*sin(10*x);
subplot(1,2,1) plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1])
y = exp(-2*x).*sin(10*x);
subplot(1,2,2) plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1]
x = [1:10];
y = [75, 58, 90, 87, 50, 85, 92, 75, 60, 95];
bar(x,y),
xlabel('Student'),ylabel('Score'), title('First Sem:')
• A contour line of a function of two variables is a curve along which the function has a constant value.
Contour lines are used for creating contour maps by joining points of equal elevation above a given
level, such as mean sea level. MATLAB provides a contour function for drawing contour maps.
• The meshgrid command is used for generating a matrix of elements that give the range over x and y
along with the specification of increment in each case.
[x,y] = meshgrid(-5:0.1:5,-3:0.1:3);
%independent variables
g = x.^2 + y.^2; % our function
contour(x,y,g)
[x,y] = meshgrid(-5:0.1:5,-3:0.1:3);
%independent variables
g = x.^2 + y.^2; % our function
[C, h] = contour(x,y,g); % call the contour
function set(h,'ShowText','on','TextStep’,
get(h,'LevelStep')*2)
[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)
DECISION MAKING
a = 10; % check the condition using if statement
if a < 20 % if condition is true then print the
following
fprintf('a is less than 20n' );
end
fprintf('value of a is : %dn', a);
Matlab_Harshal.pptx
Matlab_Harshal.pptx
Matlab_Harshal.pptx
Matlab_Harshal.pptx
Matlab_Harshal.pptx

Matlab_Harshal.pptx

  • 2.
    1. OVERVIEW • MATLAB(matrix laboratory) is a fourth-generation high-level programming language and interactive environment for numerical computation, visualization and programming. MATLAB is developed by MathWorks. • 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.
  • 3.
    MATLAB's Power ofComputational 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
  • 4.
    FEATURES OF MATLAB Followingare 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.
  • 5.
    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 • Embeded Systemd • Robotics • Computer vision • Image and video Processing • Control systems • Test and measurement • Computational finance • Computational biology
  • 6.
  • 11.
    • Naming VariablesVariable names consist of a letter followed by any number of letters, digits or underscore. MATLAB is case-sensitive. Variable names can be of any length; however, MATLAB uses only first N characters, where N is given by the function namelengthmax. • Saving Your Work The save command is used for saving all the variables in the workspace, as a file with .mat extension, in the current directory. For example, save myfile You can reload the file anytime later using the load command. load myfile
  • 26.
    PLOTTING x = [0:5:100]; y= x; plot(x, y) x = [1 2 3 4 5 6 7 8 9 10]; x = [-100:20:100]; y = x.^2; plot(x, y)
  • 27.
    x = [0:0.01:10]; y= sin(x); plot(x, y), xlabel('x'), ylabel('Sin(x)’), title('Sin(x) Graph'), grid on, axis equal x = [0 : 0.01: 10]; y = sin(x); g = cos(x); plot(x, y, x, g, '.-’), legend('Sin(x)', 'Cos(x)')
  • 28.
    MATLAB provides eightbasic color options for drawing graphs. The following table shows the colors and their codes:
  • 29.
    x = [-10: 0.01: 10]; y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9; g = 5 * x.^3 + 9 * x + 2; plot(x, y, 'r', x, g, 'g')
  • 30.
    • Setting AxisScales • axis ( [xmin xmax ymin ymax] ) x = [0 : 0.01: 10]; y = exp(-x).* sin(2*x + 3); plot(x, y), axis([0 10 -1 1])
  • 31.
    x = [0:0.01:5]; y= exp(-1.5*x).*sin(10*x); subplot(1,2,1) plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1]) y = exp(-2*x).*sin(10*x); subplot(1,2,2) plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1]
  • 32.
    x = [1:10]; y= [75, 58, 90, 87, 50, 85, 92, 75, 60, 95]; bar(x,y), xlabel('Student'),ylabel('Score'), title('First Sem:')
  • 33.
    • A contourline of a function of two variables is a curve along which the function has a constant value. Contour lines are used for creating contour maps by joining points of equal elevation above a given level, such as mean sea level. MATLAB provides a contour function for drawing contour maps. • The meshgrid command is used for generating a matrix of elements that give the range over x and y along with the specification of increment in each case. [x,y] = meshgrid(-5:0.1:5,-3:0.1:3); %independent variables g = x.^2 + y.^2; % our function contour(x,y,g)
  • 34.
    [x,y] = meshgrid(-5:0.1:5,-3:0.1:3); %independentvariables g = x.^2 + y.^2; % our function [C, h] = contour(x,y,g); % call the contour function set(h,'ShowText','on','TextStep’, get(h,'LevelStep')*2)
  • 35.
    [x,y] = meshgrid(-2:.2:2); g= x .* exp(-x.^2 - y.^2); surf(x, y, g)
  • 36.
    DECISION MAKING a =10; % check the condition using if statement if a < 20 % if condition is true then print the following fprintf('a is less than 20n' ); end fprintf('value of a is : %dn', a);