General Computer Science for Engineers CISC 106 Lecture 03

Post on 02-Jan-2016

20 views 0 download

description

General Computer Science for Engineers CISC 106 Lecture 03. James Atlas Computer and Information Sciences 9/9/2009. Objectives. Use Matlab remotely Use Basic Unix Commands Document Functions Use Conditions If statement Input/Output variables. Using Matlab Remotely (text). - PowerPoint PPT Presentation

transcript

General Computer Science General Computer Science for Engineersfor Engineers

CISC 106CISC 106Lecture 03Lecture 03

James AtlasComputer and Information Sciences

9/9/2009

ObjectivesObjectivesUse Matlab remotelyUse Basic Unix CommandsDocument FunctionsUse Conditions

◦If statementInput/Output variables

Using Matlab Remotely (text)ssh yourusername@strauss.udel.edu

◦requires an ssh program such as PuTTY◦see course website for installation details

at prompt type:matlab -nodesktop

Using Matlab Remotely (GUI)Mac users:

◦ You already have an X-Windows environmentPC users:

◦ You must setup Cygwin-X◦ Download Cygwin setup.exe from:

http://www.cygwin.com/◦ Run setup.exe and select additional packages

for: xauth xinit openssh

Running Matlab RemotelyOnce the X-Windows environment is

setup, open a terminal window and login to strauss:◦ssh -c arcfour,blowfish-cbc -YC

yourusername@strauss.udel.eduNow start Matlab:

◦matlab &

What does the & do?

EmacsEmacsTo start emacs

◦ emacs Graphical version◦ emacs –nw Text version

To open a file◦ emacs <filename>◦ emacs … then Ctrl-x Ctrl-f◦ Menu: File then “Open File…”

To save file◦ Ctrl-x Ctrl-s◦ Menu: File then “Save (current buffer)”

Exit◦ Ctrl-x Ctrl-c

Unix CommandsUnix CommandsWhen you log into a UNIX terminal

◦ You are in your home directory.◦ To see the files in your directory.

ls

◦ To make an new folder/directory. mkdir exampledir

◦ To change directories. cd exampledir

◦ To go back one directory. cd ..

◦ To go back to your home directory. cd

Handling filesHandling filescp file1 file2

◦ copy file1 and call it file2 mv file1 file2

◦ move or rename file1 to file2 rm file

◦ remove a file rmdir exampledir

◦ remove a directory cat file

◦ display contents of a file less file

◦ display a file a page at a time

Function documentationContractDescriptionExamples

Sample function circleArea.mSample function circleArea.m%circleArea(number) -> number

%Authors: James Atlas

%CISC106 Lab Section 45 TA: Scott Ivanka

%Description:

% This function computes the area of a circle

% given the radius.

%Examples:

% circleArea(3) -> 28

% circleArea(5) -> 78

% circleArea(45) -> 6362

function output = circleArea(radius)

output = pi * radius * radius;

Sample function circleArea.mSample function circleArea.m%circleArea(number) -> number

%Authors: James Atlas

%CISC106 Lab Section 45 TA: Scott Ivanka

%Description:

% This function computes the area of a circle

% given the radius.

%Examples:

% circleArea(3) -> 28

% circleArea(5) -> 78

% circleArea(45) -> 6362

function output = circleArea(radius)

output = pi * radius * radius;

Contract

Write one for function Write one for function ringArea.mringArea.mContractDescriptionExamples

ConditionsWhen you want to make a decision

based on data“If traffic light is red, stop”

ConditionsWhen you want to make a decision

based on data“If traffic light is red, stop”

◦Involves some comparison operator between data and a known value

◦known value = red◦data = current state of the traffic light◦comparison operator is “equals”

ConditionsWhen you want to make a decision

based on data“If traffic light is red, stop”

◦Involves some comparison operator between data and a known value

◦known value = red◦data = current state of the traffic light◦comparison operator is “equals”

“If current state of traffic light equals red, stop”

ConditionsIf statementOthers (will talk about later)

IF Statements in MatlabIF statements allow program to make

choices whether a condition is met or not

Basic if statement

if expression1 statements1

elseif expression2 statements2

else statements3

end

IF Statements in MatlabIF statements can be used with or

without the ELSEIF and ELSE parts

Traffic Light Examplefunction out = trafficLight(currentColor)

if (currentColor == 'R')

out = 'stop';

elseif (currentColor == 'Y')

out = 'slow';

else

out = 'go';

end

Condition operatorsequals

◦ ==not equals

◦ ~=greater than

◦ >◦ >=

less than◦ <◦ <=

Simple Input/Output

fav = input(‘Enter your favorite number\n’);

if (fav >= 0)disp(‘You like positive numbers’);

elsedisp(‘You like negative numbers’);

endfprintf(‘Your favorite number is %d’, fav);

Lab01Practice some unix commandsMatlab file sumIntsTest.m

◦an example of a “unit test”Create new functions