general computer science for engineers cisc 106 lecture 03
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 PresentationTRANSCRIPT
![Page 1: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/1.jpg)
General Computer Science General Computer Science for Engineersfor Engineers
CISC 106CISC 106Lecture 03Lecture 03
James AtlasComputer and Information Sciences
9/9/2009
![Page 2: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/2.jpg)
ObjectivesObjectivesUse Matlab remotelyUse Basic Unix CommandsDocument FunctionsUse Conditions
◦If statementInput/Output variables
![Page 3: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/3.jpg)
Using Matlab Remotely (text)ssh [email protected]
◦requires an ssh program such as PuTTY◦see course website for installation details
at prompt type:matlab -nodesktop
![Page 4: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/4.jpg)
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
![Page 5: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/5.jpg)
Running Matlab RemotelyOnce the X-Windows environment is
setup, open a terminal window and login to strauss:◦ssh -c arcfour,blowfish-cbc -YC
[email protected] start Matlab:
◦matlab &
What does the & do?
![Page 6: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/6.jpg)
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
![Page 7: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/7.jpg)
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
![Page 8: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/8.jpg)
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
![Page 9: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/9.jpg)
Function documentationContractDescriptionExamples
![Page 10: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/10.jpg)
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;
![Page 11: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/11.jpg)
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
![Page 12: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/12.jpg)
Write one for function Write one for function ringArea.mringArea.mContractDescriptionExamples
![Page 13: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/13.jpg)
![Page 14: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/14.jpg)
![Page 15: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/15.jpg)
ConditionsWhen you want to make a decision
based on data“If traffic light is red, stop”
![Page 16: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/16.jpg)
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”
![Page 17: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/17.jpg)
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”
![Page 18: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/18.jpg)
ConditionsIf statementOthers (will talk about later)
![Page 19: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/19.jpg)
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
![Page 20: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/20.jpg)
IF Statements in MatlabIF statements can be used with or
without the ELSEIF and ELSE parts
![Page 21: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/21.jpg)
Traffic Light Examplefunction out = trafficLight(currentColor)
if (currentColor == 'R')
out = 'stop';
elseif (currentColor == 'Y')
out = 'slow';
else
out = 'go';
end
![Page 22: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/22.jpg)
Condition operatorsequals
◦ ==not equals
◦ ~=greater than
◦ >◦ >=
less than◦ <◦ <=
![Page 23: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/23.jpg)
![Page 24: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/24.jpg)
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);
![Page 25: General Computer Science for Engineers CISC 106 Lecture 03](https://reader036.vdocuments.mx/reader036/viewer/2022062517/568135c1550346895d9d24cd/html5/thumbnails/25.jpg)
Lab01Practice some unix commandsMatlab file sumIntsTest.m
◦an example of a “unit test”Create new functions