Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD...

19
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham Kai Goebel, Bill Cheetham RPI/GE CRD RPI/GE CRD [email protected] [email protected] [email protected] [email protected]
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    222
  • download

    2

Transcript of Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD...

Page 1: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

1

Matlab TutorialMatlab Tutorial

Kai Goebel, Bill CheethamKai Goebel, Bill Cheetham

RPI/GE CRDRPI/GE [email protected]@cs.rpi.edu

[email protected]@cs.rpi.edu

Page 2: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

2

matlabmatlab

Start up: type “matlab”

Features:

- matrix manipulation is made easy

(data will be represented in matrices)

- plotting is made very easy

- suitable for quick prototyping

Page 3: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

3

Matlab is installed on the RCS machinesMatlab is installed on the RCS machines

1: log into an RCS account

or 2: "attach" to the RCS AFS directory structure

/usr/afsws/bin/klog <user-id-on-RCS>

provide the appropriate RCS password.

From that point, all software available on the RCS system should be available on the local machine.

Note: this attachment needs only be performed once per login session (not for every command shell opened)

Page 4: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

4

matlab tutorialmatlab tutorial

- calculations

- assignment of variables

- manipulations of variables

Page 5: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

5

matlab tutorial (2)matlab tutorial (2)- vectors

- manipulation of vectors

(addition)

- column vector

- transpose of vectors

Page 6: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

6

matlab (3)matlab (3)

- vector multiplication

- dot product

- caveat:

check inner dimensions

before operation

Page 7: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

7

matlab (4)matlab (4)

- creating matrices

from existing ones

- subtracting a constant value

from vectors

- accessing particular

matrix elements

Page 8: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

8

matlab (5)matlab (5)

- inverting matrices

- matrix power of 2

- square root

of a matrix

Page 9: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

9

Matlab (6)Matlab (6)Initializing vectors

and matrices

- known length

- unknown length

Page 10: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

10

matlab (7)matlab (7)

- checking your variables

- variables are stored

until reassigned or

when program is

terminated

- IF THEN ELSE

statements

Page 11: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

11

matlab (8)matlab (8)- FOR loops

- WHILE loops

(also note use of “<“)

- negation, OR, AND

operators

(also note prompt)

Page 12: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

12

matlab (9)matlab (9)

- plotting data

- labeling axis

- adding title

- resizing data range

Page 13: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

13

Matlab (10)Matlab (10)

Plotting one vector vs. the other

…using different markers

…and adding a legend

Page 14: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

14

matlab (11)matlab (11)

- 3-D plots

- arrange viewing direction

Page 15: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

15

matlab (12)matlab (12)- save larger operations in

text file

- invoke by typing filename

without extension

Page 16: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

16

Matlab (13)Matlab (13)

- using functions in different files

for example:

main function in

create_vector.m

subroutine in

manipulate.m

Page 17: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

17

matlab (14)matlab (14)

- load and save data files

- use of system commands

from within matlab

- print plots to file

(or to printer)

Page 18: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

18

matlab (15)matlab (15)

- HELP!

Page 19: Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD goebel@cs.rpi.educheetham@cs.rpi.edu.

Soft Computing

19

matlab (16)matlab (16)

Look for commands relating to a keyword