18
Introduction Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information. MATLAB Programming

MATLAB Programming - Software Carpentry

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Introduction

Copyright © Software Carpentry 2011This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.

MATLAB Programming

MATLAB Introduction

Good scientific software:For whom is software written?

MATLAB Introduction

Good scientific software:For whom is software written?

MATLAB Introduction

Good scientific software:For whom is software written?

1) Human readable

MATLAB Introduction

Good scientific software:For whom is software written?

1) Human readable2) Emphasizes domain and problem specific computation.

MATLAB Introduction

Good scientific software:For whom is software written?

1) Human readable2) Emphasizes domain and problem specific computation.3) Testable

MATLAB Introduction

Good scientific software:For whom is software written?

1) Human readable2) Emphasizes domain and problem specific computation.3) Testable… and then …4) Efficient

MATLAB Introduction

Bad scientific software:1) Emphasizes efficiency over readability2) Emphasizes efficiency over testability3) Reinvents the wheel4) Couples domain specific knowledge with underlying mathematical routines.

Fast, wrong code gets you the wrong answer… faster.

MATLAB Introduction

MATLAB is a …… programming language…… and a programming environment.

EncouragesReuse of tested, efficient mathematical routinesHigh level representation of programsMathematical expression over details of algorithms.

MATLAB Introduction

MATLAB the environment

MATLAB Introduction

MATLAB the environment

MATLAB Introduction

MATLAB the environment

MATLAB Introduction

MATLAB the environment

MATLAB Introduction

MATLAB as a programming language:Arrays>> nums = [1,2,3]>> nums = nums + 4;

For loops>> for i = nums:>> isprime(i);

MATLAB Introduction

Key idea: Data parallel programmingThe programmer works at level of mathematical ideas…… not loops and indices.

Most operators work on arrays directly.

Common theme: you probably* don’t want to use a loop* (exceptions apply)

MATLAB Introduction

Example:

>> for i = 1:length(arr)>> arr(i) = arr(i) * 100;>> end

Or…

>> arr = arr * 100;

MATLAB Introduction

Why learn MATLAB?Rapid prototypingScales well to large, production problems.Thousands of mathematical routines

TestedEfficient

Common language in many fields

February 2011

created by

Richard T. Guy

Copyright © Software Carpentry 2011This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.