SlideShare a Scribd company logo
1 of 46
SESSION-1


       INTRODUCTION TO
    PROGRAMMING IN MATLAB
          LANGUAGE




1                           S YADAV
Programming Basics
         To Start Matlab
         On Microsoft® Windows® platforms,
         double-clicking the MATLAB shortcut on your
          Windows desktop.


                             Matlab.ico
        On UNIX platforms, start MATLAB by typing matlab at
         the operating system prompt.
         Quitting the MATLAB Program
        To end your MATLAB session, select File > Exit
         MATLAB in the desktop, or type quit in the Command
2        Window                                          S YADAV
Programming in Matlab




 3                      S YADAV
Basics of Matlab
        Matlab has two different methods for executing commands

      Interactive mode
          In interactive mode, commands are typed (or cut-and-pasted) into the
         'command window'.
      »3+ 4
      ans =
      7


        Batch mode.
         In batch mode, a series of commands are saved in a text file (either
         using Matlab's built-in editor, or another text editor ) with a '.m'
         extension.
         The batch commands in a file are then executed by typing the name of
         the file at the Matlab command prompt.




4                                                                           S YADAV
Scripts and Functions
        M-Files:
        Files that contain code in the MATLAB language
       are called M-files. You create M-files using a text
       editor, then use them as you would any other
       MATLAB function or command.
     There are two kinds of M-files:

     1. Scripts, which do not accept input arguments or
       return output arguments. They operate on data in
       the workspace.
    2. Functions, which can accept input arguments and
       return output arguments. Internal variables are
       local to the function.
    NOTE :The names of the M-file and of the function
       should be the same.
5                                                      S YADAV
Example
     Scripts
       x = -pi:0.01:pi;
       plot(x,sin(x)), grid on



    Function
       %Name of function is sum1
       function c=sum1(a,b)
       c=a+b
       end
       M file names should be sum1.m

6                                       S YADAV
Variables
       As in programming languages, the MATLAB language provides
        mathematical expressions, but unlike most programming
        languages, these expressions involve entire matrices.
       MATLAB does not require any type declarations or dimension
        statements. When MATLAB encounters a new variable name, it
        automatically creates the variable and allocates the appropriate
        amount of storage. If the variable already exists, MATLAB changes
        its contents and, if necessary, allocates new storage. For example,
       num_students = 25 creates a 1-by-1 matrix named num_students
        and stores the value 25 in its single element.
        To view the matrix assigned to any variable, simply enter the
        variable name.
       Variable names consist of a letter, followed by any number of
        letters, digits, or underscores.(max length of variable is 63)
        MATLAB is case sensitive; it distinguishes between uppercase and
        lowercase letters. B and b are not the same variable.

7                                                                        S YADAV
MATLAB AND MATRIX



8                       S YADAV
MATRIX
    *MATLAB IS MATRIX MANIPULATION LANGUAGE.
    *MOST OF VARIABLES YOU DECLARE WILL BE
    MATRICES.
    *MATRIX IS RECTANGULAR ARRAY OF NUMBERS
    *A is MxN MATRIX : IT MEANS ‘A’ HAS M ROWS AND N
    COLUMNS
    *IN MATRIX FIRST INDEX IS ROW INDEX AND SECOND
    INDEX IS COLUMN INDEX
    *SCALAR IS 1x1 MATRIX.
    *INDEXING IN MATLAB STARTS FROM ONE(1)
9                                                  S YADAV
DEFINING MATRIX IN MATLAB
Let matrix
B=
   1   2     3
   6   7     8
B CAN BE CREATE IN MATLAB USING SYNTAX
B=[1 2 3;6 7 8];
HOW TO ACCESS DIFFERENT ELEMENTS B(ROW ,COLUMN)
B(1,1)=1 i.e. FIRST ROW and FIRST COLUMN
B(2,1)=6 i.e. SECOND ROW FIRST COLUMN
 B(2,3)=8 i.e. SECOND ROW THIRD COLUMN
10                                         S YADAV
ACCESSING SUBMATRICES
A=
  11   12      13    14       15    16
  17   18      19    20       21    22
  23   24      25    26       27    28
A(1,:) = [11    12       13    14    15    16]
i.e. FIRST ROW AND ALL COLUMNS
A(2,:)=[17     18        19   20    21    22]
i.e. SECOND ROW AND ALL COLUMNS
A(1,1:3)=[11        12    13 ];
i.e. FIRST ROW AND ONE TO THREE COLUMNS
A(2,3:6)=[19        20    21 22 ]; i.e second row , third to sixth column.
 11                                                                          S YADAV
ONE DIMENTION MATRIX

ONE DIMENTION MATRIX IS ALSO KNOWN AS VECTOR.
ONE DIMENTION MATRIX MAY BE EITHER
ROW MATRIX : CONTAINING ONE ROW ONLY
OR
COLUMN MATRIX:CONTAINING ONE COLUMN ONLY
HOW TO ACCES DIFFERENT ELEMENTS
A(1),A(2) WILL WORK AS IT IS ONE DIMENSIONAL VECTOR.

12                                            S YADAV
ALTERNATE WAY OF MAKING MATRICES


A=1:9
A=
  1     2     3   4   5   6   7    8   9
A=1:2:9
A=
  1     3     5   7   9
A=[5:-1:-5]
A=
  5     4     3   2   1   0   -1   -2 -3   -4 -5
 13                                                S YADAV
MATRIX BUILDING FUNCTIONS

    eyes(n)           will produce nxn identity matrix
eyes(m,n)         will produce mxn identity matrix
ones(n)           will produce nxn matrix of ones.
ones(m,n)         will produce mxn matrix of ones.
zeros(m,n)        will produce matrix of zeros
rand(m,n) will produce mxn matrix of randomvalue
triu(X) will extract upper triangular part of matrix X.
tril(X) will extract lower triangular part of matrix X.

14                                                 S YADAV
MATRIX OPERATIONS

+     ADDITION
-     SUBTRACTION
*     MULTIPLICATION
^     POWER
‘     CONJUGATE TRANSPOSE
.’    TRANSPOSE
     LEFT DIVISION
/     RIGHT DIVISION


THESE MATRIX OPERATIONS APPLY TO SCALARS AS WELL.
IF THE SIZES OF MATRICES ARE INCOMPATIBLE FOR THE
MATRIX OPERATION, AN ERROR MESSAGE WILL RESULT.


 15                                          S YADAV
EXAMPLE OF MULTIPLICATION
A=                    B=
 1    2                   1   1
 2    3                   1   1


A*B
      1*1+2*1   1*1+2*1
      2*1+3*1   2*1+3*1
A*B
 3    3
 5    5

16                                 S YADAV
ENTRY-WISE OPERATIONS
•OPERATIONS OF ADDITION AND SUBTRACTION ALREADY
OPERATE ENTRY WISE
A=                   B=

  1   2                  1   1
  2   1                  1   1


A+B

  2   3
  3   2




17                                          S YADAV
Other entry-wise operation

i.e.   .* , .^ , ./ ,.
A=[1 2 3 4]
B=[1 2 3 4]

A.*B=[1 4 9 16]
A=[4 6 8 10]
B=[2 2 2 2]

A./B=[2 3 4 5]
A=[1 2 3]
A.^3=[1 8 27]
 18                                            S YADAV
MATRIX DIVISION
IF A IS AN INVERTIBLE MATRIX AND b IS A COMPATIBLE
COLUMN VECTOR, then
x=Ab is the solution of A*x=b
[1 2 3;4 5 6; 8 9 7]*[x;y;z]=[1;2;3]
[x;y;z]=[1 2 3;4 5 6;8 9 7][1;2;3]


IF A IS AN INVERTIBLE MATRIX AND b IS A COMPATIBLE
ROW VECTOR, then
x=b/A is the solution of x*A=b
[x y z]*[1 2 3;4 5 6; 8 9 7]=[1 1 3]
[x y z]=[1 1 3]/[1 2 3;4 5 6;8 9 7]
 19                                              S YADAV
STATEMENTS, EXPRESIONS AND
               VARIABLES

•MATLAB is interpreted language.
•Statements are of form
   variable=expression;
   expression;
 x=3;
y=x^3+3*x;
y=sqrt(x);

Or just
x^3+2*x ;
In this case variable ‘ans’ is automatically created to which
result is assigned
 20                                                       S YADAV
Continued …..
•Statement is terminated with ‘;’
•If it is not terminated with ‘;’ , result will be displayed on
screen.
•Statements can be placed on same line if they are terminated
with ‘;’
•Single statement can be continued to next line with three or
more periods e.g. y=x*x+ …..
                2*x+3;

•MATLAB is case sensitive.
•who or whos will list variables in current workspace.
•inmem lists compiled m files in current memory.
 21                                                       S YADAV
Continued…..
•VARIABLE OR FUNCTION CAN BE CLEARED FROM
WORKSPACE
 clear variablename
 clear functionname
•clear WILL CLEAR ALL NON PERMANENT VARIABLES.
•ON LOGOUT ALL VARIABLES ARE LOST
•‘save’ WILL SAVE ALL VARIABLES IN FILE matlab.mat
•‘load’ WILL RESTORE WORKSPACE TO ITS FORMAL STATE.
•‘save’ and ‘load’ TAKE VARIABLE NAME AND FILENAME AS
OPTIONAL ARGUMENTS.
•edit fun opens the file fun.m in a text editor.


22                                                S YADAV
CONTROL STRUCTURES
          IN MATLAB



23                        S YADAV
RELATIONAL OPERATORS
<    LESS THAN
>    GREATER THAN
<=   LESS THAN OR EQUAL
>=   GREATER THAN OR EQUAL
==   EQUAL
~=   NOT EQUAL
NOTE: = IS USED IN ASSIGNMENT AND = = IS USED IN A
RELATION

LOGICAL OPERATORS
&    AND
|    OR
~    NOT
RELATIONS MAY BE CONNECTED BY LOGICAL OPERATORS


24                                                   S YADAV
OUTPUT OF RELATIONS OPRATION

WHEN APPLIED TO SCALAR, RELATION IS ZERO OR ONE
DEPENDING ON WHETHER THE RELATION IS TRUE OR FALSE
a=3; b=2;
c= ( a>b) ; It means c=1
c=(a<b); It means c=0
a= = b answer is 0
a~=b answer is 1

AND WHEN APPLIED TO MATRICES OF SAME SIZE, RELATION
IS MATRIX OF 0’s and 1’s GIVING VALUE OF RELATION
BETWEEN CORROSPONDING ENTERIES.
d=[1 2]; e=[1 1];
f= (d= =e); It means f=[1 0];


25                                            S YADAV
Control statement

    If ,if else
    For loop
    While loop
    Switch case
    Brake ,continue etc.


26                                S YADAV
IF

 price=4500;
 if price >5000,
     disp('PRICE IS MORE THAN 5000');
 end




27                                      S YADAV
IF ELSE



price=4500;
if price >5000,
  disp('PRICE IS MORE THAN 5000');
else
  disp(‘PRICE IS NOT MORE THAN 5000’);
end




 28                                      S YADAV
IF ELSEIF
price=4500;
if price >5000,
     disp('PRICE IS MORE THAN 5000');


elseif (1000<=price)&(price <=5000),
     disp('PRICE IS BETWEEN 1000 AND 5000');
else
     disp('PRICE IS LESS THAN 1000');
end


29                                             S YADAV
WHILE LOOP
var=20;
while var>0,
  disp(var);
  var=var-1;
end
disp('variable is zero now');
disp(var);



 30                                S YADAV
FOR LOOP

for i=1:10,
  disp(i);
end
for i=1:2:11,
  disp(i)
end

31                         S YADAV
Nested For Loop
n=3;
for i=1:n,
  for j=1:n,
       a(i,j)=5;
  end
end
disp(a);

32                                   S YADAV
SWITCH CASE
var1=10;
var2=5;
switch operation
case 'add'
  output=var1+var2;
  disp(output);
case {'multiply','product'}
  output=var1*var2;
  disp(output);



 33                                     S YADAV
CONTINUED ……….
case {'subtract','sub'}
  output=var1-var2;
  disp(output);
case 'divide'
  output=var1/var2;
  disp(output);
otherwise
  disp('What else you want?');
end
 34                                 S YADAV
CONTINUED…….
case {'subtract','sub'}
  output=var1-var2;
  disp(output);
case 'divide'
  output=var1/var2;
  disp(output);
otherwise
  disp('What else you want?');
end
 35                                 S YADAV
BREAK STATEMENT
var=20;
while var>0,
  disp(var);
  if var==10
      break;
  end
  var=var-1;
end
str=sprintf('Now variable is %d',var);
disp(str);

 36                                      S YADAV
FUNCTION IN MATLAB




37                   S YADAV
SCALAR FUNCTIONS
•Operate essentially on scalars.
•Operate element-wise when applied to a matrix.
sin                       asin                    exp
abs                       cos                     acos
log10                     log (natural log)       sqrt
floor                     tan                     atan
rem (remainder)           sign
round
A=sin(1)
A=
   0.8415
A=sin([1 1.2 1.3 1.4])
A=
   0.8415 0.9320 0.9636 0.9854
38                                                       S YADAV
VECTOR FUNCTIONS
•OPERATE ESSENTIALY ON VECTOR (ROW OR COLUMN)
•WHEN APPLIED TO MxN MATRIX, OPERATE COLUMN BY
COLUMN TO PRODUCE ROW VECTOR CONTAINING RESULT
OF APPLICATION TO EACH COLUMN.
max              sum              median
any              min              prod
mean             all              sort
std
max([1 2 3])
ans =
   3
max([1 2 3
      589
      7 6 2])
ans =
 39 8 9
   7                                       S YADAV
MATRIX FUNCTIONS

eig     eigenvalues and eigenvectors
chol    cholesky factorization
svd     singular value decomposition
inv     inverse
lu      LU factorization
qr      QR factorization
rref    reduced row echelon form
expm    matrix exponential

40                                     S YADAV
STRING FUNCTIONS
strcmp(str1,str2)
strncmp(str1,str2,n)
strcat(str1,str2)
str2num(str)
str2double(str)
num2str(num)
CAT(DIM,A,B) concatenates the arrays A and B along the dimension
DIM.
   CAT(2,A,B) is the same as [A,B].
   CAT(1,A,B) is the same as [A;B].




 41                                                         S YADAV
WRITING FUNCTION

function [sum,diff]= addsub(a,b)
%This function returns two outputs, sum
%and difference
sum=a+b;
diff=a-b;
return;

42                                   S YADAV
FUNCTION CONTINUED
function result=perform(operation ,var1,var2)
switch operation
case 'multiply'
   result=var1*var2;
case 'add'
   result=var1+var2;
case 'subtract'
   result=var1-var2;
case 'divide'
   result=var1/var2;
otherwise
   disp('Only multilply, add,subtract and divide operations are
allowed');
   result='error';
 43
end                                                      S YADAV
INPUT
name=input('Please enter your name : ','s');
fprintf('nHello %s !n',name);
account=input(' Please enter your account number : ');
if (25 <account)&(account<50)
  disp('Welcome');


else
  disp('You are not a valid user');
end
 44                                                  S YADAV
FORMATED OUTPUT
name=‘svits';
age=06;
salary=1800000;
fprintf('n Institute Name : %st Age : %d ….
t Salary : Rs %0.2f',name,age,salary);
fprintf('n I am writing 123456 in exponential ….
form : %e',12356);
a=[1.2 1.3 1.4 1.5 1.6];
fprintf('n %f ',a);
 45                                                 S YADAV
Thank you


46               S YADAV

More Related Content

What's hot

An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabMohan Raj
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to MatlabTariq kanher
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......biinoida
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
MatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMOHDRAFIQ22
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab OverviiewNazim Naeem
 

What's hot (20)

An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Matlab
MatlabMatlab
Matlab
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
MatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On PlottingMatLab Basic Tutorial On Plotting
MatLab Basic Tutorial On Plotting
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 

Viewers also liked

Matlab Programming Assignment help , Matlab Programming Online tutors
Matlab Programming Assignment help , Matlab Programming Online tutorsMatlab Programming Assignment help , Matlab Programming Online tutors
Matlab Programming Assignment help , Matlab Programming Online tutorsjohn mayer
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programmingSmee Kaem Chann
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Shameer Ahmed Koya
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Aman kazmi
 
aem : Fourier series of Even and Odd Function
aem :  Fourier series of Even and Odd Functionaem :  Fourier series of Even and Odd Function
aem : Fourier series of Even and Odd FunctionSukhvinder Singh
 
MATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRMATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRGhanshyam Dusane
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2Shameer Ahmed Koya
 
Licence plate recognition using matlab programming
Licence plate recognition using matlab programming Licence plate recognition using matlab programming
Licence plate recognition using matlab programming somchaturvedi
 
Product and service design
Product and service designProduct and service design
Product and service designGrace Falcis
 

Viewers also liked (13)

Matlab Programming Assignment help , Matlab Programming Online tutors
Matlab Programming Assignment help , Matlab Programming Online tutorsMatlab Programming Assignment help , Matlab Programming Online tutors
Matlab Programming Assignment help , Matlab Programming Online tutors
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programming
 
Coursee
CourseeCoursee
Coursee
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06
 
aem : Fourier series of Even and Odd Function
aem :  Fourier series of Even and Odd Functionaem :  Fourier series of Even and Odd Function
aem : Fourier series of Even and Odd Function
 
MATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRMATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCR
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Licence plate recognition using matlab programming
Licence plate recognition using matlab programming Licence plate recognition using matlab programming
Licence plate recognition using matlab programming
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Product and service design
Product and service designProduct and service design
Product and service design
 

Similar to Basics of programming in matlab

A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptxBeheraA
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabDnyanesh Patil
 
Intro to MATLAB and K-mean algorithm
Intro to MATLAB and K-mean algorithmIntro to MATLAB and K-mean algorithm
Intro to MATLAB and K-mean algorithmkhalid Shah
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2bilawalali74
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 

Similar to Basics of programming in matlab (20)

A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Matlab
MatlabMatlab
Matlab
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Intro to MATLAB and K-mean algorithm
Intro to MATLAB and K-mean algorithmIntro to MATLAB and K-mean algorithm
Intro to MATLAB and K-mean algorithm
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Matlab1
Matlab1Matlab1
Matlab1
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Basics of programming in matlab

  • 1. SESSION-1 INTRODUCTION TO PROGRAMMING IN MATLAB LANGUAGE 1 S YADAV
  • 2. Programming Basics  To Start Matlab  On Microsoft® Windows® platforms, double-clicking the MATLAB shortcut on your Windows desktop. Matlab.ico  On UNIX platforms, start MATLAB by typing matlab at the operating system prompt. Quitting the MATLAB Program  To end your MATLAB session, select File > Exit MATLAB in the desktop, or type quit in the Command 2 Window S YADAV
  • 4. Basics of Matlab  Matlab has two different methods for executing commands Interactive mode In interactive mode, commands are typed (or cut-and-pasted) into the 'command window'.  »3+ 4  ans =  7  Batch mode. In batch mode, a series of commands are saved in a text file (either using Matlab's built-in editor, or another text editor ) with a '.m' extension. The batch commands in a file are then executed by typing the name of the file at the Matlab command prompt. 4 S YADAV
  • 5. Scripts and Functions M-Files: Files that contain code in the MATLAB language are called M-files. You create M-files using a text editor, then use them as you would any other MATLAB function or command.  There are two kinds of M-files: 1. Scripts, which do not accept input arguments or return output arguments. They operate on data in the workspace. 2. Functions, which can accept input arguments and return output arguments. Internal variables are local to the function. NOTE :The names of the M-file and of the function should be the same. 5 S YADAV
  • 6. Example Scripts  x = -pi:0.01:pi;  plot(x,sin(x)), grid on Function  %Name of function is sum1  function c=sum1(a,b)  c=a+b  end  M file names should be sum1.m 6 S YADAV
  • 7. Variables  As in programming languages, the MATLAB language provides mathematical expressions, but unlike most programming languages, these expressions involve entire matrices.  MATLAB does not require any type declarations or dimension statements. When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. If the variable already exists, MATLAB changes its contents and, if necessary, allocates new storage. For example,  num_students = 25 creates a 1-by-1 matrix named num_students and stores the value 25 in its single element. To view the matrix assigned to any variable, simply enter the variable name.  Variable names consist of a letter, followed by any number of letters, digits, or underscores.(max length of variable is 63)  MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters. B and b are not the same variable. 7 S YADAV
  • 9. MATRIX *MATLAB IS MATRIX MANIPULATION LANGUAGE. *MOST OF VARIABLES YOU DECLARE WILL BE MATRICES. *MATRIX IS RECTANGULAR ARRAY OF NUMBERS *A is MxN MATRIX : IT MEANS ‘A’ HAS M ROWS AND N COLUMNS *IN MATRIX FIRST INDEX IS ROW INDEX AND SECOND INDEX IS COLUMN INDEX *SCALAR IS 1x1 MATRIX. *INDEXING IN MATLAB STARTS FROM ONE(1) 9 S YADAV
  • 10. DEFINING MATRIX IN MATLAB Let matrix B= 1 2 3 6 7 8 B CAN BE CREATE IN MATLAB USING SYNTAX B=[1 2 3;6 7 8]; HOW TO ACCESS DIFFERENT ELEMENTS B(ROW ,COLUMN) B(1,1)=1 i.e. FIRST ROW and FIRST COLUMN B(2,1)=6 i.e. SECOND ROW FIRST COLUMN B(2,3)=8 i.e. SECOND ROW THIRD COLUMN 10 S YADAV
  • 11. ACCESSING SUBMATRICES A= 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 A(1,:) = [11 12 13 14 15 16] i.e. FIRST ROW AND ALL COLUMNS A(2,:)=[17 18 19 20 21 22] i.e. SECOND ROW AND ALL COLUMNS A(1,1:3)=[11 12 13 ]; i.e. FIRST ROW AND ONE TO THREE COLUMNS A(2,3:6)=[19 20 21 22 ]; i.e second row , third to sixth column. 11 S YADAV
  • 12. ONE DIMENTION MATRIX ONE DIMENTION MATRIX IS ALSO KNOWN AS VECTOR. ONE DIMENTION MATRIX MAY BE EITHER ROW MATRIX : CONTAINING ONE ROW ONLY OR COLUMN MATRIX:CONTAINING ONE COLUMN ONLY HOW TO ACCES DIFFERENT ELEMENTS A(1),A(2) WILL WORK AS IT IS ONE DIMENSIONAL VECTOR. 12 S YADAV
  • 13. ALTERNATE WAY OF MAKING MATRICES A=1:9 A= 1 2 3 4 5 6 7 8 9 A=1:2:9 A= 1 3 5 7 9 A=[5:-1:-5] A= 5 4 3 2 1 0 -1 -2 -3 -4 -5 13 S YADAV
  • 14. MATRIX BUILDING FUNCTIONS eyes(n) will produce nxn identity matrix eyes(m,n) will produce mxn identity matrix ones(n) will produce nxn matrix of ones. ones(m,n) will produce mxn matrix of ones. zeros(m,n) will produce matrix of zeros rand(m,n) will produce mxn matrix of randomvalue triu(X) will extract upper triangular part of matrix X. tril(X) will extract lower triangular part of matrix X. 14 S YADAV
  • 15. MATRIX OPERATIONS + ADDITION - SUBTRACTION * MULTIPLICATION ^ POWER ‘ CONJUGATE TRANSPOSE .’ TRANSPOSE LEFT DIVISION / RIGHT DIVISION THESE MATRIX OPERATIONS APPLY TO SCALARS AS WELL. IF THE SIZES OF MATRICES ARE INCOMPATIBLE FOR THE MATRIX OPERATION, AN ERROR MESSAGE WILL RESULT. 15 S YADAV
  • 16. EXAMPLE OF MULTIPLICATION A= B= 1 2 1 1 2 3 1 1 A*B 1*1+2*1 1*1+2*1 2*1+3*1 2*1+3*1 A*B 3 3 5 5 16 S YADAV
  • 17. ENTRY-WISE OPERATIONS •OPERATIONS OF ADDITION AND SUBTRACTION ALREADY OPERATE ENTRY WISE A= B= 1 2 1 1 2 1 1 1 A+B 2 3 3 2 17 S YADAV
  • 18. Other entry-wise operation i.e. .* , .^ , ./ ,. A=[1 2 3 4] B=[1 2 3 4] A.*B=[1 4 9 16] A=[4 6 8 10] B=[2 2 2 2] A./B=[2 3 4 5] A=[1 2 3] A.^3=[1 8 27] 18 S YADAV
  • 19. MATRIX DIVISION IF A IS AN INVERTIBLE MATRIX AND b IS A COMPATIBLE COLUMN VECTOR, then x=Ab is the solution of A*x=b [1 2 3;4 5 6; 8 9 7]*[x;y;z]=[1;2;3] [x;y;z]=[1 2 3;4 5 6;8 9 7][1;2;3] IF A IS AN INVERTIBLE MATRIX AND b IS A COMPATIBLE ROW VECTOR, then x=b/A is the solution of x*A=b [x y z]*[1 2 3;4 5 6; 8 9 7]=[1 1 3] [x y z]=[1 1 3]/[1 2 3;4 5 6;8 9 7] 19 S YADAV
  • 20. STATEMENTS, EXPRESIONS AND VARIABLES •MATLAB is interpreted language. •Statements are of form variable=expression; expression; x=3; y=x^3+3*x; y=sqrt(x); Or just x^3+2*x ; In this case variable ‘ans’ is automatically created to which result is assigned 20 S YADAV
  • 21. Continued ….. •Statement is terminated with ‘;’ •If it is not terminated with ‘;’ , result will be displayed on screen. •Statements can be placed on same line if they are terminated with ‘;’ •Single statement can be continued to next line with three or more periods e.g. y=x*x+ ….. 2*x+3; •MATLAB is case sensitive. •who or whos will list variables in current workspace. •inmem lists compiled m files in current memory. 21 S YADAV
  • 22. Continued….. •VARIABLE OR FUNCTION CAN BE CLEARED FROM WORKSPACE clear variablename clear functionname •clear WILL CLEAR ALL NON PERMANENT VARIABLES. •ON LOGOUT ALL VARIABLES ARE LOST •‘save’ WILL SAVE ALL VARIABLES IN FILE matlab.mat •‘load’ WILL RESTORE WORKSPACE TO ITS FORMAL STATE. •‘save’ and ‘load’ TAKE VARIABLE NAME AND FILENAME AS OPTIONAL ARGUMENTS. •edit fun opens the file fun.m in a text editor. 22 S YADAV
  • 23. CONTROL STRUCTURES IN MATLAB 23 S YADAV
  • 24. RELATIONAL OPERATORS < LESS THAN > GREATER THAN <= LESS THAN OR EQUAL >= GREATER THAN OR EQUAL == EQUAL ~= NOT EQUAL NOTE: = IS USED IN ASSIGNMENT AND = = IS USED IN A RELATION LOGICAL OPERATORS & AND | OR ~ NOT RELATIONS MAY BE CONNECTED BY LOGICAL OPERATORS 24 S YADAV
  • 25. OUTPUT OF RELATIONS OPRATION WHEN APPLIED TO SCALAR, RELATION IS ZERO OR ONE DEPENDING ON WHETHER THE RELATION IS TRUE OR FALSE a=3; b=2; c= ( a>b) ; It means c=1 c=(a<b); It means c=0 a= = b answer is 0 a~=b answer is 1 AND WHEN APPLIED TO MATRICES OF SAME SIZE, RELATION IS MATRIX OF 0’s and 1’s GIVING VALUE OF RELATION BETWEEN CORROSPONDING ENTERIES. d=[1 2]; e=[1 1]; f= (d= =e); It means f=[1 0]; 25 S YADAV
  • 26. Control statement  If ,if else  For loop  While loop  Switch case  Brake ,continue etc. 26 S YADAV
  • 27. IF price=4500; if price >5000, disp('PRICE IS MORE THAN 5000'); end 27 S YADAV
  • 28. IF ELSE price=4500; if price >5000, disp('PRICE IS MORE THAN 5000'); else disp(‘PRICE IS NOT MORE THAN 5000’); end 28 S YADAV
  • 29. IF ELSEIF price=4500; if price >5000, disp('PRICE IS MORE THAN 5000'); elseif (1000<=price)&(price <=5000), disp('PRICE IS BETWEEN 1000 AND 5000'); else disp('PRICE IS LESS THAN 1000'); end 29 S YADAV
  • 30. WHILE LOOP var=20; while var>0, disp(var); var=var-1; end disp('variable is zero now'); disp(var); 30 S YADAV
  • 31. FOR LOOP for i=1:10, disp(i); end for i=1:2:11, disp(i) end 31 S YADAV
  • 32. Nested For Loop n=3; for i=1:n, for j=1:n, a(i,j)=5; end end disp(a); 32 S YADAV
  • 33. SWITCH CASE var1=10; var2=5; switch operation case 'add' output=var1+var2; disp(output); case {'multiply','product'} output=var1*var2; disp(output); 33 S YADAV
  • 34. CONTINUED ………. case {'subtract','sub'} output=var1-var2; disp(output); case 'divide' output=var1/var2; disp(output); otherwise disp('What else you want?'); end 34 S YADAV
  • 35. CONTINUED……. case {'subtract','sub'} output=var1-var2; disp(output); case 'divide' output=var1/var2; disp(output); otherwise disp('What else you want?'); end 35 S YADAV
  • 36. BREAK STATEMENT var=20; while var>0, disp(var); if var==10 break; end var=var-1; end str=sprintf('Now variable is %d',var); disp(str); 36 S YADAV
  • 38. SCALAR FUNCTIONS •Operate essentially on scalars. •Operate element-wise when applied to a matrix. sin asin exp abs cos acos log10 log (natural log) sqrt floor tan atan rem (remainder) sign round A=sin(1) A= 0.8415 A=sin([1 1.2 1.3 1.4]) A= 0.8415 0.9320 0.9636 0.9854 38 S YADAV
  • 39. VECTOR FUNCTIONS •OPERATE ESSENTIALY ON VECTOR (ROW OR COLUMN) •WHEN APPLIED TO MxN MATRIX, OPERATE COLUMN BY COLUMN TO PRODUCE ROW VECTOR CONTAINING RESULT OF APPLICATION TO EACH COLUMN. max sum median any min prod mean all sort std max([1 2 3]) ans = 3 max([1 2 3 589 7 6 2]) ans = 39 8 9 7 S YADAV
  • 40. MATRIX FUNCTIONS eig eigenvalues and eigenvectors chol cholesky factorization svd singular value decomposition inv inverse lu LU factorization qr QR factorization rref reduced row echelon form expm matrix exponential 40 S YADAV
  • 41. STRING FUNCTIONS strcmp(str1,str2) strncmp(str1,str2,n) strcat(str1,str2) str2num(str) str2double(str) num2str(num) CAT(DIM,A,B) concatenates the arrays A and B along the dimension DIM. CAT(2,A,B) is the same as [A,B]. CAT(1,A,B) is the same as [A;B]. 41 S YADAV
  • 42. WRITING FUNCTION function [sum,diff]= addsub(a,b) %This function returns two outputs, sum %and difference sum=a+b; diff=a-b; return; 42 S YADAV
  • 43. FUNCTION CONTINUED function result=perform(operation ,var1,var2) switch operation case 'multiply' result=var1*var2; case 'add' result=var1+var2; case 'subtract' result=var1-var2; case 'divide' result=var1/var2; otherwise disp('Only multilply, add,subtract and divide operations are allowed'); result='error'; 43 end S YADAV
  • 44. INPUT name=input('Please enter your name : ','s'); fprintf('nHello %s !n',name); account=input(' Please enter your account number : '); if (25 <account)&(account<50) disp('Welcome'); else disp('You are not a valid user'); end 44 S YADAV
  • 45. FORMATED OUTPUT name=‘svits'; age=06; salary=1800000; fprintf('n Institute Name : %st Age : %d …. t Salary : Rs %0.2f',name,age,salary); fprintf('n I am writing 123456 in exponential …. form : %e',12356); a=[1.2 1.3 1.4 1.5 1.6]; fprintf('n %f ',a); 45 S YADAV
  • 46. Thank you 46 S YADAV