0% found this document useful (0 votes)
168 views69 pages

22MAT11

The document provides information about a MATLAB manual for a course at the Mangalore Institute of Technology & Engineering. It includes the course code, faculty teaching the course, laboratory experiments covered, course learning objectives, and an introduction to MATLAB that outlines how to access and use MATLAB. It also discusses basic MATLAB syntax, built-in math functions, symbolic math toolbox, and creating symbolic numbers, variables, expressions, functions, and arrays.

Uploaded by

Mr Spam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views69 pages

22MAT11

The document provides information about a MATLAB manual for a course at the Mangalore Institute of Technology & Engineering. It includes the course code, faculty teaching the course, laboratory experiments covered, course learning objectives, and an introduction to MATLAB that outlines how to access and use MATLAB. It also discusses basic MATLAB syntax, built-in math functions, symbolic math toolbox, and creating symbolic numbers, variables, expressions, functions, and arrays.

Uploaded by

Mr Spam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

MANGALORE INSTITUTE OF TECHNOLOGY & ENGINEERING

Accredited by NAAC with A+ Grade, An ISO 9001: 2015 Certified Institution


A unit of Rajalaxmi Education Trust, Mangalore
Badaga Mijar, Moodabidri, Dakshina Kannada Dist - Karnataka
Department of Mathematics

MATLAB MANUAL
First Semester
2022-2023

Mangalore Institute of Technology & Engineering, Moodabidri 2


Department of Mathematics

MATLAB MANUAL
First Semester
2022-2023

Mangalore Institute of Technology & Engineering, Moodabidri 3


course title : Mathematics for cse stream-1
course code : 22mats11

Department of Mathematics
Faculty
Dr. Jyothi S
Dr. Vasanth Kumar S
Mrs. Rashmi Praveen
Mrs. Anusha
Ms. Shamitha Shetty
Ms. Swathy Shetty
Dr. Girija K P
Dr. Nagarjun Prabhu
Mr. Venkatramana P B
Dr. Chaitanya S Nayak
Mangalore Institute of Technology & Engineering, Moodabidri
List of Laboratory Experiments

1.2D plots for Cartesian and polar curves.


2.Finding angle between polar curves, curvature
and radius of curvature of a given curve.
3.Finding partial derivatives, Jacobian and plotting
the graph.
4.Applications to Maxima and Minima of two
variables.
5.Solution of first-order differential equation and
plotting the graphs. 5
Mangalore Institute of Technology & Engineering, Moodabidri
List of Laboratory Experiments

6. Finding GCD using Euclid’s Algorithm.


7. Applications of Wilson's theorem.
8. Numerical solution of system of linear equations,
test for consistency and graphical representation.
9. Solution of system of linear equations using Gauss-
Seidel iteration.
10. Compute eigenvalues and eigenvectors and find
the largest and smallest eigenvalue by Rayleigh
6
Mangalore Institute of Technology & Engineering, Moodabidri
Course Learning Objectives

1. Illustrate fundamentals of MATLAB


programming and write simple programs
2. Solve complex mathematical problems
associated with Polar curves, Partial
differentiation, Ordinary differential equations,
Integral calculus(EC), Modular Arithmetic(CS),
Linear algebra and compare the results with that
of solutions obtained using MATLAB

7
Mangalore Institute of Technology & Engineering, Moodabidri
Introduction to MATLAB

• The name MATLAB stands for MATrix LABoratory.


• MATLAB is a software package for high-performance
numerical computation and visualization.
• It provides an interactive environment with hundreds of built-
in functions for technical computation, graphics and
animation.
• Best of all, it also offers easy extensibility with its own high-
level programming language.

8
Mangalore Institute of Technology & Engineering, Moodabidri
Introduction to MATLAB

• It has powerful built-in routines that enable a very wide


variety of computations.
• It possesses easy-to-use graphics commands that make the
visualization of results immediately available.
• Specific applications are executed using tool boxes, which are
a collection of routines that are designed to do common
things.

9
Mangalore Institute of Technology & Engineering, Moodabidri
Introduction to MATLAB

• There are toolboxes for signal processing, symbolic


computation, control theory, simulation, optimization and
several other fields of applied science and engineering.

10
Mangalore Institute of Technology & Engineering, Moodabidri
How to access
MATLAB R2022b

The next two sections outline instructions on obtaining


access to MATLAB.
Associate to the Campus-Wide License:
1. Open the Mathworks
2. Click on “Get MATLAB”
3. Create account using your MITE email address
(Candidate id- [email protected])

11
Mangalore Institute of Technology & Engineering, Moodabidri
How to access
MATLAB R2022b

4. You will get an verification email from Mathworks


account create request
5. Sign in using your MathWorks Account with your
MITE email address.
6. Once logged into the Portal, you would
automatically be associated to the MITE MATLAB
Campus-Wide License.

12
Mangalore Institute of Technology & Engineering, Moodabidri
How to open and save files?

• In the toolbar of MATLAB window, the options ‘HOME’ or


‘EDITOR/LIVE EDITOR’ possess the icon which is to ‘open’ a
file with ‘.m’ or ‘.mlx’ extension. The particular file gets loaded in
editor window.
• A click on the icon saves the file.
• While saving file do not remove ‘.m’ or ‘.mlx’

Mangalore Institute of Technology & Engineering, Moodabidri


Basic Syntax - Using MATLAB

Operations Symbol Examples Operations Symbol Examples


Addition + 3+2 = 5 Right division / 1/2
Subtraction - 5-1 = 4 Left division \ 2\6 = 6/2 = 3
Multiplication * 4*6 = 24 Exponentiation ^ 5^3 = 125
Mangalore Institute of Technology & Engineering, Moodabidri
Elementary Math Built-In
Function
Syntax and description:
• sin - Sine
• sind - Sine of argument in degrees
• sinh - Hyperbolic sine
• asin - Inverse sine
• asind - Inverse sine, result in degrees
• asinh - Inverse hyperbolic sine
• cos - Cosine
• tan - Tangent
Mangalore Institute of Technology & Engineering, Moodabidri
Elementary Math Built-In
Function
• sec - Secant
• csc - Cosecant
• cot - Cotangent
• exp - Exponential
• log - Natural logarithm
• log10 - Common (base 10) logarithm
• sqrt - Square root
• abs - Absolute value
• imag - Complex imaginary part
• real - Complex real part
16
Mangalore Institute of Technology & Engineering, Moodabidri
Comment (%)

Mangalore Institute of Technology & Engineering, Moodabidri


clc, clear, clear all

18
Mangalore Institute of Technology & Engineering, Moodabidri
Introduction to math toolbox

• Using the symbolic Math Toolbox we can create Symbolic


Objects

Types of Symbolic Objects:

1. Symbolic Numbers

2. Symbolic Variables

3. Symbolic Expressions- Equations or Functions

4. Symbolic Arrays
19
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Numbers
• To store a number as symbolic number in
workspace, we define the syntax sym(x).
• In following example, we see in first ‘x’ is stored
with default 4 decimal places and then as fraction
with sym(x) syntax.

20
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Variables
• In workspace to store x, a, b and c as symbol and value as x, a, b and c,
we use the syntax ‘’syms’’
• In general, if not defined MATLAB will assume given variable as a
matrix.
• We define “ syms x a b c ”
Then in workspace x, a, b and c is stored as symbol and value as x, a, b
and c.

21
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Equations
• To store a general Quadratic equations, we write
• syms x a b c
• f =a*x^2+ b*x + c
• If the required polynomial is f=5x^2-2x +7, then to
substitute old values a, b and c as 5, -2 and 7 we
use “subs” syntax. i.e.,

• Write in square bracket when you have more than


one value to be substituted.
22
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Functions
• To represent a function in x variable symbolically,
we write
“ syms f(x) ”

Firstly, we define the function as in previous slide.


Then we call the function by “ f(x)=f_1 ”.

But then to obtain the function value at any point ‘c’


we write as f(c) and run the program. For example,

23
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Functions

24
Mangalore Institute of Technology & Engineering, Moodabidri
Symbolic Arrays
• To symbolize any array we use “ syms ” syntax.
• For example, to write a Circulant Matrix of order 3 by 3 with a, b
and c as symbols, we use the following:

25
Mangalore Institute of Technology & Engineering, Moodabidri
Practice Problems

Construct
• A row matrix
• A column matrix
• A square matrix
• A rectangular matrix
• Addition of matrices
• Subtraction of matrices
• Multiplication of matrices
26
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing

27
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing

28
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing

29
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing
To find the diagonal elements

30
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing

31
Mangalore Institute of Technology & Engineering, Moodabidri
Array Indexing

32
Mangalore Institute of Technology & Engineering, Moodabidri
Array Concatenation
Techniques

There are two types of Array Concatenation


1. Horizontal : For successful concatenation, all
the arrays to be concatenated must have same
number of rows.
2.Vertical : For successful concatenation, all the
arrays to be concatenated must have same
number of columns

33
Mangalore Institute of Technology & Engineering, Moodabidri
Array Concatenation
Techniques

34
Mangalore Institute of Technology & Engineering, Moodabidri
2D plots for Cartesian
and polar curves
• Objectives
Use MATLAB
1. To plot 2D Cartesian curves.
2. To plot 2D polar curves.
3. To plot implicit functions.

35
Mangalore Institute of Technology & Engineering, Moodabidri
2D plots for Cartesian
and polar curves
• Syntex for the commands used
2dplot-fplot()
2dplot of symbolic expressions-fplot()

36
Mangalore Institute of Technology & Engineering, Moodabidri
2D plots for Cartesian
and polar curves
How to plot Straight line

MATLAB will consider the Default range as -5 to 5 37


2D plots for Cartesian
and polar curves
How to go with specific
interval

38
2D plots for Cartesian
and polar curves
Exponential function

39
2D plots for Cartesian
and polar curves
Logarithmic function

40
2D plots for Cartesian
and polar curves
Trigonometric function

41
2D plots for Cartesian
and polar curves
Trigonometric function

42
2D plots for Cartesian
and polar curves
Trigonometric function

43
2D plots for Cartesian
and polar curves
Explicit function plot
Create a 2-D line plot by using fplot

Plot the expression x^3 − 6x^2 + 11x − 6

44
2D plots for Cartesian
and polar curves

45
2D plots for Cartesian
and polar curves
Implicit function plot
Create a 2-D line plot by
using fplot

46
2D plots for Cartesian
and polar curves
Implicit function plot

Plot the equation (x^2 + y^2)^4 =


(x^2 − y^2)^2 over −1 < x < 1.

47
2D plots for Cartesian
and polar curves
Plot Parametric curve
Plot 2-D parmetetric curve by
using fplot

48
2D plots for Cartesian
and polar curves

49
2D plots for Cartesian
and polar curves
3-D Plot

50
2D plots for Cartesian
and polar curves
Create Surface Plot
Create a 3-D surface by using
fsurf
Plot the paraboloid z = x^2 + y^2

51
2D plots for Cartesian
and polar curves

52
2D plots for Cartesian
and polar curves

53
2D plots for Cartesian
and polar curves

54
Mangalore Institute of Technology & Engineering, Moodabidri
Differentiation

How to find the derivative of any function using MatLab


Syntax using for differentiation is “diff( )”

55
Differentiation

56
Mangalore Institute of Technology & Engineering, Moodabidri
Differentiation

57
Mangalore Institute of Technology & Engineering, Moodabidri
Differentiation

58
Mangalore Institute of Technology & Engineering, Moodabidri
Differentiation

59
Mangalore Institute of Technology & Engineering, Moodabidri
Differentiation

60
Mangalore Institute of Technology & Engineering, Moodabidri
How to find the angle
between two curves

61
Mangalore Institute of Technology & Engineering, Moodabidri
How to find the angle
between two curves

62
Mangalore Institute of Technology & Engineering, Moodabidri
How to find the angle
between two curves

63
Mangalore Institute of Technology & Engineering, Moodabidri
How to find the angle
between two curves

64
Mangalore Institute of Technology & Engineering, Moodabidri
Working with Arrays
and Matrices

1. Array Creation
2. Indexing Arrays
3. Array Creation Functions
4. Array Concatenation Techniques

65
Mangalore Institute of Technology & Engineering, Moodabidri
Array Creation
Create a row/column/m*n array of four elements: -6, 0, 6, 9

66
Mangalore Institute of Technology & Engineering, Moodabidri
Array Creation

67
Mangalore Institute of Technology & Engineering, Moodabidri
Array Creation

68
Mangalore Institute of Technology & Engineering, Moodabidri
Thank you

MANGALORE INSTITUTE OF TECHNOLOGY & ENGINEERING

You might also like