matlab for the sciences - · pdf filematlab for the sciences an introduction to matlab jon m....

12
Introduction Initial Variables MATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 Jon M. Ernstberger MATLAB for the Sciences

Upload: vuthuan

Post on 13-Mar-2018

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

MATLAB for the SciencesAn Introduction to MATLAB

Jon M. Ernstberger

January 5, 2008

Jon M. Ernstberger MATLAB for the Sciences

Page 2: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

Introduction

What is MATLAB?

Where does it come from?

What does MATLAB mean?

Why is it useful?

Who makes MATLAB?

Jon M. Ernstberger MATLAB for the Sciences

Page 3: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

The w’s...

Figure: Random MATLAB Figure

Created by Clive Moler inthe late 1970s.

The idea was to give CSstudents an easy way ofaccessing Fortran softwaresuch as LINPACK.

Portmanteau for MATrixLABoratory

Jon M. Ernstberger MATLAB for the Sciences

Page 4: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

Why use MATLAB?

http://www.mathworks.com/products/matlab/

Pros

Very high level!Rapid developement. Easy to write code and generate results.Graphical output is quick and easy.Make text-based output very easy (LATEX, html, Excel)

Cons

Most numerical computation is written in C. You mustinterface with some well-known softwares.MATLAB is, in fact, Java-driven and is inherently slower thanthe fastest programming languages.Must have solid hardware.Expense. $599 for the standard version. Each toolbox is anadditional $100.

Jon M. Ernstberger MATLAB for the Sciences

Page 5: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

InstallationHelp and Documentation

Installation

You will need:

A Personal License Passcode (PLP)

Installation DVD

Ample Hardisk Space

Computer With Sufficient Hardware Requirements

Jon M. Ernstberger MATLAB for the Sciences

Page 6: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

InstallationHelp and Documentation

Get it Started!

Jon M. Ernstberger MATLAB for the Sciences

Page 7: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

InstallationHelp and Documentation

MATLAB Help

Perhaps your most used resource in MATLAB.

At the MATLAB window type

help exp

Jon M. Ernstberger MATLAB for the Sciences

Page 8: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

InstallationHelp and Documentation

MATLAB Documentation

Similarly, at the MATLAB window, type

doc exp

The documentation is typically more detailed with more help.

Jon M. Ernstberger MATLAB for the Sciences

Page 9: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

Declaring Variables

Dynamic Typing

MATLAB is dynamically typed. You do not have to define yourvariables explicitly.

Standard Precision

MATLAB does arithmetic using a standard double-precisionarithmetic (accurate to about 15 places past the decimal).

Jon M. Ernstberger MATLAB for the Sciences

Page 10: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

Declaring Variables,cont.

Constants. In the MATLAB window, type

x=1;

First notice “=”.Second notice “;”. What happens without “;”?This is really a 1× 1 matrix.

Matrices. In the MATLAB window, type

A=[1,2;3,4];

cd

What do the “[” and “]” do?What about the “,” and “;”?How might I create a 4x4 matrix that has the numbersascending in value from 1 to 16?

Jon M. Ernstberger MATLAB for the Sciences

Page 11: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

Workspace

Figure: Variables declared and showing up in the “workspace” block.

Note the following:

MATLAB will help you keep track of variable usage.

MATLAB will tell you the type of the variable in use.

MATLAB will tell you the dimension of the vector variable.

Jon M. Ernstberger MATLAB for the Sciences

Page 12: MATLAB for the Sciences - · PDF fileMATLAB for the Sciences An Introduction to MATLAB Jon M. Ernstberger January 5, 2008 ... Excel) Cons Most numerical computation is written in C

IntroductionInitial

Variables

In-Class Exercises

Work on these in groups of 2-3.

Attempt to find three good online references for MATLABusage.

Do a ’help sin’ in the terminal and then evaluate at 2π (hint:use ’help’ or ’Google’ to figure out how to input π).

Do a ’doc sin’ at the command line.

Jon M. Ernstberger MATLAB for the Sciences