Presentation is loading. Please wait.

Presentation is loading. Please wait.

General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 9/9/2009.

Similar presentations


Presentation on theme: "General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 9/9/2009."— Presentation transcript:

1 General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 9/9/2009

2 Objectives Use Matlab remotely Use Basic Unix Commands Document Functions Use Conditions ◦ If statement Input/Output variables

3 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

4 Using Matlab Remotely (GUI) Mac users: ◦ You already have an X-Windows environment PC 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

5 Running Matlab Remotely Once the X-Windows environment is setup, open a terminal window and login to strauss: ◦ ssh -c arcfour,blowfish-cbc -YC yourusername@strauss.udel.edu Now start Matlab: ◦ matlab & What does the & do?

6 Emacs To start emacs ◦ emacs Graphical version ◦ emacs –nw Text version To open a file ◦ emacs ◦ 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

7 Unix Commands When 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

8 Handling files cp 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

9 Function documentation Contract Description Examples

10 Sample 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;

11 Sample 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

12 Write one for function ringArea.m Contract Description Examples

13

14

15 Conditions When you want to make a decision based on data “If traffic light is red, stop”

16 Conditions When 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”

17 Conditions When 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”

18 Conditions If statement Others (will talk about later)

19 IF Statements in Matlab IF 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

20 IF Statements in Matlab IF statements can be used with or without the ELSEIF and ELSE parts

21 Traffic Light Example function out = trafficLight(currentColor) if (currentColor == 'R') out = 'stop'; elseif (currentColor == 'Y') out = 'slow'; else out = 'go'; end

22 Condition operators equals ◦ == not equals ◦ ~= greater than ◦ > ◦ >= less than ◦ < ◦ <=

23

24 Simple Input/Output fav = input(‘Enter your favorite number\n’); if (fav >= 0) disp(‘You like positive numbers’); else disp(‘You like negative numbers’); end fprintf(‘Your favorite number is %d’, fav);

25 Lab01 Practice some unix commands Matlab file sumIntsTest.m ◦ an example of a “unit test” Create new functions


Download ppt "General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 9/9/2009."

Similar presentations


Ads by Google