Ciencia

Páginas: 14 (3475 palabras) Publicado: 11 de diciembre de 2012
Beginning Matlab Exercises
R. J. Braun
Department of Mathematical Sciences
University of Delaware

1

Introduction

This collection of exercises is intended to help you start learning Matlab. Matlab is a huge package with
many capabilities, but it is easy to use on many levels.
The text indicated by the numbers will be Matlab commands that you can input to the Matlab
prompt. text willindicate quantities that you need to replace with in a Matlab command. Text to the
right of a % symbol are comments and need not be typed at the prompt unless you wish to have the comment
in a diary or other file.
In nearly all cases, no output will be shown; that’s for you to find!

2

Getting Started

In the computer classroom, you can start Matlab by opening a terminal window and thentyping the
appropriate command. Typing the command matlab followed by will start Matlab using its
window manager. In this mode, you can find helpful pull down menus across the top of the window (or
desktop). The default configuration has one main command window, and two other windows that allow
access to the workspace, command history, current directory and launch pad.
Typing the command matlab-nojvm runs Matlab without the window manager. This can avoid some
annoying bugs in the window manager that may appear (particularly in linux) on starting up. This will give
only the command window; plots will appear in separate graphics windows in both modes.
To exit, use the pull down menu under File or type the command exit in the command window.

3

Scalar arithmetic

Matlab can beused as a calculator. Some of the problems indicate the precedence of arithmetic operations.
1. 3*2^4
2. (3*2)^4

% parentheses have highest priority

3. 3-2^4
4. 3^4-3
5. 8/2^4
6. 2^4\8

% same as previous! two different divisions, \ and /

7. 8^4/2
Precedence of arithmetic operations is: (1) parentheses, (2) exponentiation, (3) multiplication and division, and (4) addition andsubtraction. Calculations proceed from left to right on the line and equal
precedence is settled in this way.

4

Vectors

It will typically be that our basic unit for computing will be a vector. We need to be able to create and
manipulate them.

1

4.1

Creating vectors

1. x = [3 4 7 11]

% create a row vector (spaces)

2. x = 3:8

% colon generates list; default stride 1

3.x = 8:-1:0

% start : stride : stop specifies list

4. xx = [ 8 7 6 5 4 3 2 1 0];

%

same as last; semicolon suppresses output

5. xx

% display contents

6. x = linspace(0,1,11)

% generate vector automatically

7. x = 0:0.1:1

% same thing

8. y = linspace(0,1);

% note semicolon!

9. length(x)
10. length(y)
11. size(x)
12. size(y)
13. y(3)

% access singleelement

14. y(1:12)

% access first twelve elements

15. y([3 6 9 12])

% access values specified in a vector!

16. x’

% transpose

17. z = [ 1+2*i 4-3*i ]
18. z’
19. z.’

% note difference in transposes!

20. 3*[1 2 5]

% factor replicated, multiplies each element

Matlab labels the arrays (vectors and matrices) beginning with 1; this will be an important programming
detailon more than one occasion.

4.2

Help with vectors and other things

Matlab has extensive online help; try these commands to get help at the command line. If the window
manager is running in Matlab, you can also get browser-based interactive help. Try both.
1. help help

%

try Matlab’s extensive help

2. help length
3. help size
4. help linspace
5. help logspace
6. help clc
7.help clear
8. help who
2

9. help whos
Note that Matlab help is also available in html format by using the menu bar at the top of the desktop.
The help is more comprehensive in the browser-based help, but it is sometimes harder to find if you already
know the command name.

5

Functions and plotting

5.1

Elementary functions in Matlab

1. help elfun
2. Use the following few...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Ciencia ciencia
  • Ciencia ciencia
  • Ciencia O Ciencias
  • Ciencias Ciencias
  • Ciencia o No Ciencia
  • la ciencia y las ciencias
  • Ciencias
  • Ciencias

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS