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 2/17/2010.

Similar presentations


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

1 General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 2/17/2010

2 Operations on Data Types 5.5 single(5.5) int8(5) int8(500) ? int8(‘c’) ? char(98) ? >> x = 5.5 >> whos x

3 Expressions Data and Operator ◦ 2 + 2 ◦ circleArea(5)

4 Expressions Data and Operator ◦ 2 + 2 ◦ circleArea(5) Nested Expressions ◦ circleArea(circleArea(5 + 2) + circleArea(3))

5 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

6 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

7 Function documentation Contract Purpose Examples Author

8 Sample function circleArea.m %circleArea(number) -> number % This function computes the area of a circle % given the radius. % % circleArea(3) -> 28 % circleArea(5) -> 78 % circleArea(45) -> 6362 % %Authors: James Atlas %CISC106 Lab Section 45 TA: Scott Ivanka function output = circleArea(radius) output = pi * radius * radius;

9 Sample function circleArea.m %circleArea(number) -> number % This function computes the area of a circle % given the radius. % % circleArea(3) -> 28 % circleArea(5) -> 78 % circleArea(45) -> 6362 % %Authors: James Atlas %CISC106 Lab Section 45 TA: Scott Ivanka function output = circleArea(radius) output = pi * radius * radius; Contract Purpose

10 Group Exercise

11 Write one for function ringArea.m Contract Description Examples

12

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

14 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”

15 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”

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

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

18

19 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);

20 Lab01 Practice some unix commands Matlab file test_sumThreeInts.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 2/17/2010."

Similar presentations


Ads by Google