68
CHAPTER 1 INTRODUCTION 1.1 Overview 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. 1.2 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 1.3 Feature of MATLAB

1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

  • Upload
    buidiep

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

CHAPTER 1

INTRODUCTION

1.1Overview

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.

1.2 MATLAB's Power of Computational MathematicsMATLAB 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

1.3 Feature 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.

Page 2: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

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.

1.4 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

1.5MATLAB Installation Steps

Open MATLAB software folder. Click on Setup option. Then to select without using the internet option. Click on next button. Then click on accept agree button. Then, for installation key < Go to MATLAB folder >, next< Go to crack folder >, <

open install.txt file >, < Select any one Key>. Copy one key and paste in installation key option. Select either Typical or Custom option. Click on Yes button. Then again open same dialogue box and then we select same option, without internet

option. Provide Path folder and Select Standalone file. Click on Finish Button.

Page 3: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

CHAPTER 2

MATLAB ENVIRONMENT

2.1 Understanding the MATLAB Environment When you launch MATLAB you are presented with the MATLAB desktop which, by

default, is divide into 4 windows:

2.1.1 Command Window: - This is the main window, and contains the commands prompt

(?). This is where you will type all commands.

2.1.2 Command History: - It displays a list of previously typed commands. The command

history persists across multiple sessions and commands can be dragged into the commands

window and edited, or doubled- clicked to run them again.

2.1.3 Workspace: - Lists all the variables you have generated in the current session. It shows

the type and size of variables, and can be used to quickly plot, or inspect the values of

variables.

2.1.4 Current Folder: - A line of code or its output can exceed the width of the command

window, requiring you to use the horizontal scroll bar to view the entire line. To break single

line of input or output into multiple lines to fit within the current width of the command

window:

On the Home tab, in the Environment section, select Preference > command window.

Select Wrap lines.

Click OK

2.2 BASIC SYNTAXType a valid expression, for example,2.2.1 % Adding two numbers>> 10+5And press Enter.MATLAB executes it immediately and the result returned is: Ans= 152.2.2 % Subtraction of two numbers>> 36-24MATLAB executes it immediately and the result returned is: Ans= 122.2.3 % Multiplication of two numbers>> 7132*30.4MATLAB executes it immediately and the result returned is: Ans=2.1681e+052.2.4 % Divide by Zero>>8/0And press Enter MATLAB executes it immediately and the result returned is:

Page 4: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Ans= Inf

2.2.5 % Cube 4 raised to the power 3>>4^3And press EnterMATLAB executes it immediately and the result returned is: Ans=64

2.2.6 Sin of angle 90 degree>>sin (pi/2)

And press enter.

MATLAB executes it immediately and the result returned is: Ans=1

>>Sin (2*pi)

Ans=-2.4493e-16

2.3 Commonly Used Operators and Special Characters

Operator Description

+ Addition or unary plus. A+B adds the values stored in variables A and B. A and B must have the same size, unless one is a scalar. A scalar can be added to a matrix of any size.

- Subtraction or unary minus. A-B subtracts the value of B from A. A and B must have the same size, unless one is a scalar. A scalar can be subtracted from a matrix of any size.

* Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B. More precisely,

For non-scalar A and B, the number of columns of A must be equal to the number of rows of B. A scalar can multiply a matrix of any size.

.* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of them is a scalar.

/ Slash or matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A'\B')'.

./ Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B must have the same size, unless one of them is a scalar.

\ Backslash or matrix left division. If A is a square matrix, A\B is roughly the same as inv(A)*B, except it is computed in a different way. If A is an n-by-n matrix and

Page 5: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

B is a column vector with n components, or a matrix with several such columns, then X = A\B is the solution to the equation AX = B. A warning message is displayed if A is badly scaled or nearly singular.

.\ Array left division. A.\B is the matrix with elements B(i,j)/A(i,j). A and B must have the same size, unless one of them is a scalar.

^ Matrix power. X^p is X to the power p, if p is a scalar. If p is an integer, the power is computed by repeated squaring. If the integer is negative, X is inverted first. For other values of p, the calculation involves eigenvalues and eigenvectors, such that if [V,D] = eig(X), then X^p = V*D.^p/V.

.^ Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. A and B must have the same size, unless one of them is a scalar.

' Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the complex conjugate transpose.

.' Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve conjugation.

2.4Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. MATLAB is designed to operate primarily on whole matrices and arrays. Therefore, operators in MATLAB work both on scalar and non-scalar data. MATLAB allows the following types of elementary operations −

Arithmetic Operators Relational Operators Logical Operators Bitwise Operations Set Operations

2.4.1 Arithmetic Operators

MATLAB allows two different types of arithmetic operations −

Matrix arithmetic operations Array arithmetic operations

Matrix arithmetic operations are same as defined in linear algebra. Array operations are executed element by element, both on one-dimensional and multidimensional array.

Page 6: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

The matrix operators and array operators are differentiated by the period (.) symbol. However, as the addition and subtraction operation is same for matrices and arrays, the operator is same for both cases. 

2.4.2 SET Operators

MATLAB provides various functions for set operations, like union, intersection and testing for set membership, etc.The following table shows some commonly used set operations −Show Examples

Function Description

intersect(A,B) Set intersection of two arrays; returns the values common to both A and B. The values returned are in sorted order.

intersect(A,B,'rows') Treats each row of A and each row of B as single entities and returns the rows common to both A and B. The rows of the returned matrix are in sorted order.

ismember(A,B) Returns an array the same size as A, containing 1 (true) where the elements of A are found in B. Elsewhere, it returns 0 (false).

ismember(A,B,'rows') Treats each row of A and each row of B as single entities and returns a vector containing 1 (true) where the rows of matrix A are also rows of B. Elsewhere, it returns 0 (false).

issorted(A) Returns logical 1 (true) if the elements of A are in sorted order and logical 0 (false) otherwise. Input A can be a vector or an N-by-1 or 1-by-N cell array of strings. A is considered to be sorted if A and the output of sort(A) are equal.

issorted(A, 'rows') Returns logical 1 (true) if the rows of two-dimensional matrix A is in sorted order, and logical 0 (false) otherwise. Matrix A is considered to be sorted if A and the output of sort rows (A) are equal.

setdiff(A,B) Sets difference of two arrays; returns the values in A that are not in B. The values in the returned array are in sorted order.

setdiff(A,B,'rows') Treats each row of A and each row of B as single entities and returns the rows from A that are not in B. The rows of the returned matrix are in sorted order.The 'rows' option does not support cell arrays.

setxor Sets exclusive OR of two arrays

union Sets union of two arrays

unique Unique values in array

Page 7: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

2.4.3 Input and Output Commands

MATLAB provides the following input and output related commands −

Command Purpose

disp Displays contents of an array or string.

fscanf Read formatted data from a file.

format Controls screen-display format.

fprintf Performs formatted writes to screen or file.

input Displays prompts and waits for input.

; Suppresses screen printing.

2.4.3.1 Disp Commanddisp (x) displays the array, without printing the array name. In all other ways it’s the name. In

all other semicolon off an expression except that empty arrays don’t display. If x is a string,

the text is displayed.

Example: >> X=’Hello world ’;

>>disp(X)

HELLO WORLD

2.4.3.2 INPUT COMMAND Input command prompt for user input.

Page 8: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

NUM=input (prompt)

Displays the PROMPT string on the screen, waits for input from the keyboard, evaluates any

expression in the input, and returns the value in NUM. To evaluate expressions, inout

accesses variables in the current workspace. If you press the return key without entering

anything, input returns an empty matrix.

STR=input (PROMPT,’s’)

Returns the entered text as a MATLAB string without evaluating expressions.

For Example: -

>> Name = input (‘Enter your name :’, ‘s’);

Enter your Name :Maniksha

CHAPTER 3

MATLAB BASIC PROGRAMS

Page 9: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.1 Addition of Two Numbers

In this program, addition of two numbers using variables a and b. Put these values in Editor

Window.

a = 20

b = 10

c=a+b

Results shown in Command Window

a = 20

b = 10

c=30

3.2 Subtraction of Two Numbers

Page 10: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, subtraction of two numbers using variables a and b. Put these values in

Editor Window.

a = 20

b = 10

c=a-b

Results shown in Command Window

a = 20

b = 10

c= 10

3.3 Multiplication of Two Numbers

Page 11: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, multiplication of two numbers using variables a and b. Put these values in

Editor Window.

a = 5

b = 5

c=a*b

Results shown in Command Window

a = 5

b = 5

c= 25

3.4 Divide Two Numbers

Page 12: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, dividation of two numbers using variables a and b. Put these values in Editor

Window.

a = 25

b = 5

c=a/b

Results shown in Command Window

a = 25

b = 5

c= 5

3.5 Addition of Two Numbers using Array creation

Page 13: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, addition of two numbers using array with variables a and b. Put these values

in Editor Window.

a = [1 2 3 4 5]

b = [6 7 8 9 5]

c=a+b

Results shown in Command Window

a = 1 2 3 4 5

b = 6 7 8 9 5

c= 7 9 11 13 10

3.6 Subtraction of Two Numbers using Array creation

Page 14: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, subtraction of two numbers using array with variables a and b. Put these

values in Editor Window.

a = [2 4 6 8 10]

b = [1 3 5 7 9]

c=a-b

Results shown in Command Window

a = 2 4 6 8 10

b = 1 3 5 7 9

c= 1 1 1 1 1

3.7 Multiplication of Two Numbers using Array creation

Page 15: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, multiplication of two numbers using array with variables a and b. Put these

values in Editor Window.

a = [2 5 7 9 10]

b = [1 4 6 8 2]

c=a.*b

Results shown in Command Window

a = [2 5 7 9 10]

b = [1 4 6 8 2]

c= [2 20 42 72 20]

3.8 Divide Two Numbers using Array creation

Page 16: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, dividation of two numbers using array with variables a and b. Put these

values in Editor Window.

a = [25 30 40 80 100]

b = [5 6 10 8 10]

c=a./b

Results shown in Command Window

a = [25 30 40 80 100]

b = [5 6 10 8 10]

c= [5 5 4 10 10]

3.9 Basic Formula Implemented: d= (a+b )2

Page 17: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:d= (a+b )2 with variables a, b & c. Put these

values in Editor Window.

a = [2 4 6 8 10]

b = [2 4 6 8 10]

c=a+b

d=c.^2

Results shown in Command Window

a = [2 4 6 8 10]

b = [2 4 6 8 10]

c= [4 8 12 16 20]

d= [16 64 144 256 400]

3.10 Basic Formula Implemented: d= (a−b )2

Page 18: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:d= (a−b )2 with variables a, b & c. Put these

values in Editor Window.

a = [10 20 30 40 50]

b = [5 10 15 20 25]

c= a-b

d=c.^2

Results shown in Command Window

a = [10 20 30 40 50]

b = [5 10 15 20 25]

c= [5 10 15 20 25]

d= [25 100 225 400 625]

3.11 Basic Formula Implemented: m=( a2+b2 )

Page 19: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:m=( a2+b2 ) with variables i, j, k, l. Put these

values in Editor Window.

i = [2 4 6 8 10]

j = [3 5 7 9 10]

k=i.^2

l=j.^2

m=k+l

Results shown in Command Window

i = [2 4 6 8 10]

j = [3 5 7 9 10]

k= [4 16 36 64 100]

l= [9 25 49 81 100]

m= [13 41 85 145 200]

3.12 Basic Formula Implemented: e=( a2−b2 )

Page 20: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:e=( a2−b2 ) with variables a,b,c,&d. Put these

values in Editor Window.

a = [8 4 6 8 10]

b = [2 2 3 4 5]

c =a.^2

d =b.^2

e=c-d

Results shown in Command Window

a = [8 4 6 8 10]

b = [2 2 3 4 5]

c = [64 16 36 64 100]

d= [4 4 9 16 25]

e= [60 12 27 48 75]

3.13 Basic Formula Implemented: d= (a+b )3

Page 21: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:d= (a+b )3 with variables a, b & c. Put these

values in Editor Window.

a = [2 3 4 5]

b = [1 2 3 4]

c=a+b

d=c.^3

Results shown in Command Window

a = [2 3 4 5]

b = [1 2 3 4]

c= [3 5 7 9]

d= [27 125 343 729]

3.14 Basic Formula Implemented: d= (a−b )3

Page 22: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:d= (a−b )3 with variables a, b & c. Put these

values in Editor Window.

a = [4 8 12 16]

b = [2 4 4 4 ]

c= a-b

d=c.^3

Results shown in Command Window

a = [4 8 12 16]

b = [2 4 4 4]

c= [2 4 8 12]

d= [8 64 512 1728]

3.15 Basic Formula Implemented: e=( a3+b3 )

Page 23: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:e=( a3+b3 ) with variables a, b, c & d . Put these

values in Editor Window.

a = [2 4 6 8 ]

b = [2 4 6 8]

c=a.^3

d=b.^3

e=c+d

Results shown in Command Window

a = [2 4 6 8]

b = [2 4 6 8]

c= [8 64 216 512]

d= [8 64 216 512]

e= [16 128 432 1024]

3.16 Basic Formula Implemented: e=( a3−b3 )

Page 24: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:e=( a3−b3 ) with variables a,b,c,&d. Put these

values in Editor Window.

a = [4 8 16 20]

b = [2 4 8 10]

c =a.^3

d =b.^3

e =c-d

Results shown in Command Window

a = [4 8 16 20]

b = [2 4 8 10]

c = [64 512 4096 8000]

d= [8 64 512 1000]

e= [56 448 3584 7000]

3.17 Basic Formula Implemented: t=√ 1n

√ab+cd+deabcd

Page 25: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, basic formula implemented:t=√ 1n

√ab+cd+deabcd

with variables a, b, c,

d&some others. Put these values in Editor Window.

a = 10

b = 20

c =5

d =10

e=20

f=30

n=20

Results shown in Command Window

p=0.0500

q=1.4577e

t=0.0121

Page 26: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.18 Basic Formula Implemented: q=√ √ab+ 3√cd+(ef )2

3√ab+cd+ef

In this program, basic formula implemented:q=√ √ab+ 3√cd+(ef )2

3√ab+cd+ef with variables a,b,c,d

&some others. Put these values in Editor Window.

a = 20 b = 30

c = 10 d = 20

e = 40 f = 80

Results shown in Command Window:

m=15.8740

0=1.0240e

p=6.4509e

q=803.1720

Page 27: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.19 Basic Formula Implemented: q=∑i=1

10

x (i )

In this program, basic formula implemented:q=∑i=1

10

x (i) with variables I, p,& x . Put these

values in Editor Window.

x= [1 2 3 4 5 6 8 9 10 90]

i= 1:10

p= x (i)

q= sum (p)

Results shown in Command Window

x= [1 2 3 4 5 6 8 9 10 90]

p= [1 2 3 4 5 6 8 9 10 90]

q= 138

Page 28: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.20 Basic Formula Implemented: w=∑i=1

10

¿¿

In this program, basic formula implemented:w=∑i=1

10

¿¿ with variables I, p, q, w x, y z . Put

these values in Editor Window.

x= [1 2 3 4 5 6 7 8 9 10]

i= 1:10

p= x (i)

y=[2 3 6 8 1 3 5 7 9 1]

q=y(i)

z=p+q

z1=z.^2

Results shown in Command Window

x= [1 2 3 4 5 6 7 8 9 10]

y= [2 3 6 8 1 3 5 7 9 1]

z= [3 6 9 12 6 9 12 15 18 11]

z1= [9 36 81 144 36 81 144 225 324 121]

w= 1201

Page 29: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.21 Basic Formula Implemented by using loop: ∑i=1j=1

j=2i=3

x ( i , j )

In this program, basic formula implemented by using loop: : ∑i=1j=1

j=2i=3

x ( i , j ) with variable x & p .

Put these values in Editor Window.

x= [1 2;4 5;7 8]

p= 0

i= 1:3

j= 1:2

p= p+x(i,j)

s= sum(p)

Results shown in Command Window

x= [1 2;4 5;7 8 ]

Page 30: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

p= 27

s= 27

3.22 Basic Formula Implemented by using loop:

q 1=(1/n√∑m=1n=1

n=3m=4

x (m ,n )−∑k=1i=1

i=2k=2

x (k , i))

In this program, basic formula implemented by using loop :

q 1=(1/n√∑m=1n=1

n=3m=4

x (m ,n )−∑k=1i=1

i=2k=2

x (k , i)) with variable, j, k, l, m, n, q, t1 . Put these values in

Editor Window.

x= [1 2 3;4 5 6;7 8 9;1 2 3]

p= 0

j= 0

Page 31: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Results shown in Command Window:

q=0.0500

q1=0.03122

3.23 Basic Formula Implemented by using loop : q=∑i=1

10

x (i)

In this program, basic formula implemented by using loop:q=∑i=1

10

x (i) with variables I, p,& x

. Put these values in Editor Window.

x= [1 2 3 4 5 6 7 8 9 10]

i= 1:10

p= x (i)

Page 32: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

q= sum (p)

Results shown in Command Window

x= [1 2 3 4 5 6 8 9 10 90]

p= [55]

q= [55]

3.24 Basic Formula Implemented by using loop:z1=√1/n[∑k=4

k=11

x (k )+∑j=1n=1

n=4j=2

y ( j , n)]

In this program, basic formula implemented by using loop: z1=

√1/n[∑k=4

k=11

x (k )+∑j=1n=1

n=4j=2

y ( j , n)] with variable x & y . Put these values in Editor Window.

Page 33: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

x= [1 2 3 4 5 6 7 8 9 10 11]

y= [1 2 3 4;5 6 7 8]

Results shown in Command Window

Z1 =2.1909

3.25 Input calling Function for Addition.

In this program, addition of two numbers using input calling function with variables a and b.

Put these values in Editor Window.

a1 = [1 2 3 4 5]

b1= [1 2 3 4 5]

c1=a1+b1

Page 34: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Results shown in Command Window

a1 = [1 2 3 4 5]

b1 = [1 2 3 4 5]

c1= [2 3 6 8 10]

3.26 Input calling Function for Subtraction.

In this program, subtraction of two numbers using input calling function with variables a and

b. Put these values in Editor Window.

a = [1 2 3 4 5]

b= [1 2 3 4 5]

Page 35: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

c=a- b

Results shown in Command Window

a = [1 2 3 4 5]

b = [1 2 3 4 5]

c= [0 0 0 0 0]

3.27 Input calling Function for Multiplication.

In this program, multiplication of two numbers using input calling function with variables a

and b. Put these values in Editor Window.

a = [1 2 3 4 5]

b= [1 2 3 4 5]

c=a.*b

Page 36: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Results shown in Command Window

a = [1 2 3 4 5]

b = [1 2 3 4 5]

c= [1 4 9 16 25]

3.28 Input calling Function for Divide.

In this program, divide of two numbers using input calling function with variables a and b.

Put these values in Editor Window.

a = 78

b= 16

Page 37: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

c=a/b

Results shown in Command Window

a = 78

b = 16

c= 4.8750

3.29 Input calling Function for Submission.

In this program, submission of two numbers using input calling function with variables i and

x. Put these values in Editor Window.

i= 1:4

x=[1 2 3 4 5 6 7]

p=x(i)

p1=sum(p)

Page 38: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Results shown in Command Window

i = [1 2 3 4]

x = [1 2 3 4 5 6 7]

p= [1 2 3 4]

p1=10

3.30 Input calling Function for Submission using loop.

In this program, submission of two numbers using input calling function using loop with

variables i and x. Put these values in Editor Window.

i= 1:4

x=[1 2 3 4 5 ]

Page 39: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

p=0

Results shown in Command Window

i = [4]

x = [1 2 3 4 5 ]

p= [10]

3.31 Program for continuous graph using input command.

In this program, continuous graph created using input calling function with variables a and b.

Put these values in Editor Window.

a=[1 2 3 4 5]

b=[1 2 3 4 5]

Page 40: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

plot(a,b)

Results shown in Command Window

a=[1 2 3 4 5]

b=[1 2 3 4 5]

3.32 Program for discrete graph using input command.

In this program, discrete graph created using input calling function with variables a and b. Put

these values in Editor Window.

a=[1 2 3 4 5]

b=[1 2 3 4 5]

Page 41: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

stem (a,b)

Results shown in Command Window.

a=[1 2 3 4 5]

b=[1 2 3 4 5]

3.33 Program for label, title, color, marker line, legend command by using continuous

graph.

In this program, continious graph created using input calling function with variables a and b.

Put these values in Editor Window.

a=[1 2 3 4 5]

b=[1 2 3 4 5]

plot (a, b)

Results shown in Command Window.

Page 42: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

a=[1 2 3 4 5]

b=[1 2 3 4 5]

3.34 Program for label, title, color, marker line, legend command by using discrete

graph.

In this program, discrete graph created using input calling function with variables a and b. Put

these values in Editor Window.

a=[1 2 3 4 5]

Page 43: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

b=[1 2 3 4 5]

stem (a, b)

Results shown in Command Window.

a=[1 2 3 4 5]

b=[1 2 3 4 5]

3.35 Program for showing an image.

Page 44: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, image is showing with the help of variable a. Put the command in Editor

Window.

a= imread(‘path where the image is store’)

imshow(a)

Results shown in figure window.

3.36 Program for showing an image and change it’s colour .

Page 45: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

In this program, image is showing and change it’s colour with the help of variable a and b.

Put the command in Editor Window.

a= imread(‘path where the image is store’)

b=rgb2gray(a)

imshow(b)

Results shown in figure window.

3.37 Program for showing two images at same time .

In this program, two image is showing at same time with the help of variable a and b. Put the

command in Editor Window.

Page 46: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

a= imread(‘path where the image is store’)

imshow(a)

figure

b=rgb2gray(a);

imshow(b)

Results shown in two figure window.

3.38 Program for showing two or more images at same time in one figure window.

In this program, two or more image is showing at same time in one figure window with the

help of variable a and b. Put the command in Editor Window.

Subplot(2,1,1)

a= imread(‘path where the image is store’)

Page 47: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

imshow(a)

subplot(2,1,2)

b=rgb2gray(a);

imshow(b)

Results shown in one figure window.

CHAPTER 3

GRAPHIC USER INTERFACE

GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of

software applications, eliminating the need to learn a language or type commands in order to

run the application. MATLAB apps are self-contained MATLAB programs with GUI front

ends that automate a task or calculation.

3.1 STEPS TO CREATE GUI PANEL First Click On Guide Select Default Blank Click On Next Button After Open Guide window ,Then Click on Panel option Button Then Select Whole window to create panel window. After Create panel then click on Run button. After Run the panel, Then Editor window will open. Write your program on editor window. When you complete your program then click on again Run button. Program start. Finish.

3.1.1 Some Screenshot how to create GUI: -

Page 48: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Create Blank GUI

GUI Open, Then select panel.

Select Panel

Click on Run

Page 49: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

Write your program in

editor window

Then click again Run Button

Your Program shown like this

Page 50: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2 IMAGE DATA PROCESSThe basic MATLAB data structure is the array, an ordered set of real or complex elements.

An array -is naturally suited to the representation of images, real-valued, ordered sets of color

or intensity data (an array is suited for complex valued images) in the MATLAB workspace,

most images are represent-ted as 2-D arrays (matrices), in which each elements of the matrix

corresponds to a single pixel in the displayed image. For example, an image composed of

200 rows and 300 columns of different colored dots stored as a 200 by 300 matrix. Some

images, such as RGB, require 3-D arrays, where the first plane in the third dimension

represents the red pixel intensities, the second plane represents the green pixel intensities,

and the third plane represents the blue pixel intensities.

3.2.1 STEP TO CREATE GUI IMAGE DATA Select Guide

Select Panel

After Create your panel ,Then Click on Run Button

Then Automatically Open editor window, for write you a Program.

Then after click on Run button.

3.2.2SOME COMMAND USE IN GUI IMAGE DATA

a.imread(‘file name’)

b. imshow(__)

For Example 1st :-

a=imread(‘C:\Users\DELL\Desktop\dd.JPG’)

Imshow(a)

Exampe 2nd For Black & White : -

b=imread(‘C:\Users\DELL\Desktop\dd.JPG’)

c=rgb2gray(b)

imshow(c)

Page 51: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2 Some screenshots of GUI:

3.2.1 create a Blank GUI

Page 52: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2.2 GUI open, Then select a Panel

3.2.3 click on Run

Page 53: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2.4 Write your program in editor window and again click on Run

Page 54: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2.5 Your program shown like this:

Page 55: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation
Page 56: 1.2 MATLAB's Power of Computational Mathematicsd2automation.in/embedded/matlab word file.docx  · Web viewCHAPTER 1. INTRODUCTION. Overview. MATLAB (matrix laboratory) is a fourth-generation

3.2.7 When you click on CLOSE button, then your window will close automatically.