Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Matlab Part 1-Mathematical Modeling and Simulation-Lecture Slides, Slides of Mathematical Modeling and Simulation

These lecture slides are delivered at The LNM Institute of Information Technology by Dr. Sham Thakur for subject of Mathematical Modeling and Simulation. Its main points are: Matlab, Numerical, Computing, Environment, Matrix, Mathematics, Graphics, Desktop, Command, Window

Typology: Slides

2011/2012

Uploaded on 07/03/2012

jaee
jaee 🇮🇳

4.7

(22)

101 documents

1 / 43

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Slides
on
Modeling and Simulation
Lecture: Introduction to Matlab
Part - 1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download Introduction to Matlab Part 1-Mathematical Modeling and Simulation-Lecture Slides and more Slides Mathematical Modeling and Simulation in PDF only on Docsity!

Lecture Slides

on

Modeling and Simulation

Lecture: Introduction to Matlab Part - 1

Preview

Introduction

Where to use MATLAB

  • Math and computation
  • Algorithm development
  • Data acquisition
  • Modeling, simulation, and prototyping
  • Data analysis, exploration, and visualization
  • Scientific and engineering graphics
  • Application development, including graphical user interface building

Introduction

MATLAB system:

Integrative Development Environment (IDE) MATLAB Mathematical Function Library

  • Including Bassel functions and fast Fourier Transformation MATLAB Language
  • high-level matrix/array language
  • object-oriented Graphics
  • display vectors and matrices as graphs API
  • C/Fortran program can interact with MATHLAB

Introduction - Desktop

  • Command Window
    • enter variables
    • run functions/M-files
      • Command History
        • View statements
        • Save: diary('filename')

Introduction -- Desktop

Editor/Debugger:

sum, transpose, and diag

Special properties of a magic square have to do with the various ways of summing its elements. If you take the sum along any row or column, or along either of the two main diagonals, you will always get the same number. Let us verify that using MATLAB. The first statement to try is sum(A)

MATLAB replies with

ans = 34 34 34 34

When you do not specify an output variable, MATLAB uses the variable ans, short for answer, to store the results of a calculation.

You have computed a row vector containing the sums of the columns of A. Sure enough, each of the columns has the same sum, the magic sum, 34.

Transpose

The transpose operation is denoted by an apostrophe or single quote, '. It flips a matrix about its main diagonal and it turns a row vector into a column vector.

So

A'

produces

ans = 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1

Subscripts

The element in row i and column j of A is denoted by A(i,j).

For example, A(4,2) is the number in the fourth row and second column.

For our magic square, A(4,2) is 15.

So to compute the sum of the elements in the fourth column of A, type

A(1,4) + A(2,4) + A(3,4) + A(4,4)

This produces

ans =

34

but is not the most elegant way of summing a single column.

Matrix

If you try to use the value of an element outside of the matrix, it is an error: t = A(4,5) Index exceeds matrix dimensions.

On the other hand, if you store a value in an element outside of the matrix, the size increases to accommodate the newcomer: X = A; X(4,5) = 17 X = 16 3 2 13 0 5 10 11 8 0 9 6 7 12 0 4 15 14 1 17

Expressions

Like most other programming languages, MATLAB provides mathematical expressions, but unlike most programming languages, these expressions involve entire matrices. The building blocks of expressions are

  • Variables
  • Numbers
  • Operators
  • Functions

See also Examples of Expressions in Help.

Variable name

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. MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters A and a are not the same variable.

Operators

Expressions use familiar arithmetic operators and precedence rules.

  • Addition
  • Subtraction
  • Multiplication

/ Division

\ Left division (described in "Matrices and Linear Algebra" in the MATLAB documentation) ^ Power

' Complex conjugate transpose

() Specify evaluation order

Functions

MATLAB provides a large number of standard elementary mathematical functions, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a negative number is not an error; the appropriate complex result is produced automatically. MATLAB also provides many more advanced mathematical functions, including Bessel and gamma functions. Most of these functions accept complex arguments. For a list of the elementary mathematical functions, type

help elfun

For a list of more advanced mathematical and matrix functions, type

help specfun

help elmat

Some of the functions, like sqrt and sin, are built in.

Built-in functions are part of the MATLAB core so they are very efficient, but the computational details are not readily accessible. Other functions, like gamma and sinh, are implemented in M-files.