This action might not be possible to undo. Are you sure you want to continue?

CANCEL

OK

Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more

Download

Standard view

Full view

of .

Look up keyword or section

Like this

Share on social networks

94Activity

×

0 of .

Results for: No results containing your search query

P. 1

MatlabRatings:

(0)|Views: 1,654|Likes: 106

Published by rdfd4545454

See more

See less

https://www.scribd.com/doc/34370810/Matlab

12/27/2014

text

original

(March 30, 2010 2:47p.m.)

AMATLABTutorial

Ed OvermanDepartment of MathematicsThe Ohio State University

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 31 Scalar Calculations . . . . . . . . . . . . . . . . . . . . . . 6

1.1 Simple Arithmetical Operations . . . . . . . . . . . . . . . . . 61.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . 71.3 Round-oﬀ Errors . . . . . . . . . . . . . . . . . . . . . . 91.4 Formatting Printing . . . . . . . . . . . . . . . . . . . . . 101.5 Common Mathematical Functions . . . . . . . . . . . . . . . . . 111.6 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . 131.7 Script M-ﬁles . . . . . . . . . . . . . . . . . . . . . . . 131.8 Help! . . . . . . . . . . . . . . . . . . . . . . . . . . 141.9 Be Able To Do . . . . . . . . . . . . . . . . . . . . . . . 16

2 Arrays: Vector and Matrix Calculations . . . . . . . . . . . . . . . 16

2.1 Generating Matrices . . . . . . . . . . . . . . . . . . . . . 172.2 The Colon Operator . . . . . . . . . . . . . . . . . . . . . 212.3 Manipulating Matrices . . . . . . . . . . . . . . . . . . . . 212.4 Simple Arithmetical Operations . . . . . . . . . . . . . . . . . 252.5 Operator Precedence . . . . . . . . . . . . . . . . . . . . . 292.6 Be Careful! . . . . . . . . . . . . . . . . . . . . . . . . 292.7 Common Mathematical Functions . . . . . . . . . . . . . . . . . 312.8 Data Manipulation Commands . . . . . . . . . . . . . . . . . . 322.9 Advanced Topic: Multidimensional Arrays . . . . . . . . . . . . . . 342.10 Be Able To Do . . . . . . . . . . . . . . . . . . . . . . 35

3 Anonymous Functions, Strings, and Other Data Types . . . . . . . . . . 36

3.1 Anonymous Functions . . . . . . . . . . . . . . . . . . . . 373.2 Passing Functions as Arguments to Commands . . . . . . . . . . . . . 383.3 Strings . . . . . . . . . . . . . . . . . . . . . . . . . 393.4 Advanced Topic: Cell Arrays and Structures . . . . . . . . . . . . . . 40

4 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.1 Two-Dimensional Graphics . . . . . . . . . . . . . . . . . . . 434.2 Three-Dimensional Graphics . . . . . . . . . . . . . . . . . . 494.3 Advanced Graphics Techniques: Commands . . . . . . . . . . . . . . 514.4 Advanced Graphics Techniques: Handles and Properties . . . . . . . . . . 554.5 Be Able To Do . . . . . . . . . . . . . . . . . . . . . . . 56

5 Solving Linear Systems of Equations . . . . . . . . . . . . . . . . 57

5.1 Square Linear Systems . . . . . . . . . . . . . . . . . . . . 575.2 Catastrophic Round-Oﬀ Errors . . . . . . . . . . . . . . . . . . 605.3 Overdetermined and Underdetermined Linear Systems . . . . . . . . . . . 61

6 File Input-Output . . . . . . . . . . . . . . . . . . . . . . 637 Some Useful Linear Algebra Commands . . . . . . . . . . . . . . . 658 Programming in MATLAB . . . . . . . . . . . . . . . . . . . 71

8.1 Flow Control and Logical Variables . . . . . . . . . . . . . . . . 718.2 Matrix Relational Operators and Logical Operators . . . . . . . . . . . . 758.3 Function M-ﬁles . . . . . . . . . . . . . . . . . . . . . . 798.4 Odds and Ends . . . . . . . . . . . . . . . . . . . . . . 888.5 Advanced Topic: Vectorizing Code . . . . . . . . . . . . . . . . . 90

9 Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . 92

10 Initial-Value Ordinary Diﬀerential Equations . . . . . . . . . . . . . 95

10.1 Basic Commands . . . . . . . . . . . . . . . . . . . . . . 9510.2 Advanced Commands . . . . . . . . . . . . . . . . . . . . 100

11 Boundary-Value Ordinary Diﬀerential Equations . . . . . . . . . . . 10612 Polynomials and Polynomial Functions . . . . . . . . . . . . . . . 11013 Numerical Operations on Functions . . . . . . . . . . . . . . . . 11214 Discrete Fourier Transform . . . . . . . . . . . . . . . . . . . 11515 Mathematical Functions Applied to Matrices . . . . . . . . . . . . . 122Appendix: Reference Tables . . . . . . . . . . . . . . . . . . . . 125Solutions To Exercises . . . . . . . . . . . . . . . . . . . . . . 137ASCII Table . . . . . . . . . . . . . . . . . . . . . . . . . 139Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

2

Introduction

MATLAB is an interactive software package which was developed to perform numerical calculationson vectors and matrices. Initially, it was simply a MATrix LABoratory. However, today it is much morepowerful:

•

It can do quite sophisticated graphics in two and three dimensions.

•

It contains a high-level programming language (a “baby C”) which makes it quite easy to code com-plicated algorithms involving vectors and matrices.

•

It can numerically solve nonlinear initial-value ordinary diﬀerential equations.

•

It can numerically solve nonlinear boundary-value ordinary diﬀerential equations.

•

It contains a wide variety of toolboxes which allow it to perform a wide range of applications from sci-ence and engineering. Since users can write their own toolboxes, the breadth of applications is quiteamazing.Mathematics is the basic building block of science and engineering, and MATLAB makes it easy to handlemany of the computations involved. You should not think of MATLAB as another complication program-ming language, but as a powerful calculator that gives you ﬁngertip access to exploring interesting prob-lems in science, engineering, and mathematics. And this access is available by using only a small numberof commands and function

†

because MATLAB’s basic data element is a matrix (or an array).This is a crucial feature of MATLAB — it was designed to group large amounts of data in arrays andto perform mathematical operations on this data as individual arrays rather than as groups of data. Thismakes it very easy to apply complicated operations to the data, and it make it very diﬃcult to do itwrong. In high-level computer languages you would usually have to work on each piece of data separatelyand use loops to cycle over all the pieces. In MATLAB this can frequently do complicated “things” inone, or a few, statements (and no loops). In addition, in a high-level language many mathematical op-erations require the use of sophisticated software packages, which you have to ﬁnd and, much worse, to

understand

since the interfaces to these packages are frequently quite complicated and the documentationmust be read and mastered. In MATLAB, on the other hand, these operations have simple and consistentinterfaces which are quite easy to master. For an overview of the capabilities of MATLAB, type

>> demo

in the

Help Navigator

and click on

MATLAB

.This tutorial is designed to be a concise introduction to many of the capabilities of MATLAB. It makesno attempt to cover either the range of topics or the depth of detail that you can ﬁnd in a reference man-ual, such as

Mastering MATLAB 7

by Duane Hanselman and Bruce Littleﬁeld (which is over 850 pageslong) or

MATLAB Guide, 2nd edition

by Desmond and Nicholas Higham (which is almost 400 pages long).This tutorial was initially written to provide students with a

free

“basic” overview of commands whichare useful in an undergraduate course on linear algebra. Over the years it has grown to include courses inordinary diﬀerential equations, mathematical modelling, and numerical analysis. It also includes an intro-duction to two- and three-dimensional graphics because graphics is often the preferred way to present theresults of calculations.In this tutorial MATLAB is ﬁrst introduced as a calculator and then as a plotting package. Only after-wards are more technical topics discussed. We take this approach because most people are quite familiarwith calculators, and it is only a small step to understand how to apply these same techniques to matricesrather than individual numbers or varibles. In addition, by viewing MATLAB as a simple but powerfulcalculater, rather than as a complicated software package or computer language, you will be in the correctframe of mind to use MATLAB.You should view MATLAB as a tool that you are “playing with” — trying ideas out and seeing how

†

There is a technical distinction between a

command

and a

function

in MATLAB: input arguments to com-mands are not enclosed in parentheses (they are separated by spaces) and there are no output arguments (i.e., acommand cannot be on the right-hand side of an equal sign). In reality, this is a very ﬁne distinction since manycommands can be written as functions by putting the arguments between parentheses and separating them withcommas. We will generally use the term

functions

unless there is a reason to make a distinction.

3

You've already reviewed this. Edit your review.

1 hundred reads

1 thousand reads

Chandan Kumar liked this

Pranav Mehta liked this

dheerajosu liked this

Mitzias Thanasis liked this

El Arbi Abdellaoui Alaoui liked this

Kreetha Traison liked this

Cancio Florez liked this

Chandan Kumar liked this

- Read and print without ads
- Download to keep your version
- Edit, email or read offline

MATLAB Fundamentals

MATLAB Programming

LaplaceTransforms with MATLAB

Modeling and Simulation of Systems Using MATLAB and Simulink

Computational Physics Using MATLAB

Matlab Tutorial

Applied Numerical Methods With MATLAB for Engineers and Scientists

matlab

Numerical Mathematics With MATLAB

Matlab

Thinking in Python

Circuit Analysis I With MATLAB Applications

Computational Fluid Mechanics - Malestrom

Numerical Analysis Using MATLAB and Spreadsheets 2E-Mathematic87.Blogfa

Advanced Engg Maths With MATLAB

MATLAB - A Fundamental Tool for Scientific Computing and Engineering Applications - Volume 2

Finite Element Analysis of Composite Laminates 0792311256

Fundamental Finite Element Analysis and Applications

Introduction to Numerical Ordinary and Partial Differential Equations Using MATLAB

Fund Ls Engi Ng Thermodynamics

Partial Differential Equations Analytical and Numerical Methods

Chapra Applied Numerical Methods MATLAB 2rd Edition

MATLAB Tutorial

MATLAB and Simulink

Matlab

Numerical Methods using MATLAB

MATLAB Programming

Matlab

Learn MATLAB

Mechanics of Laminated Composite Plates and Shells

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

CANCEL

OK

You've been reading!

NO, THANKS

OK

scribd