1 / 25

General Computer Science for Engineers CISC 106 Lecture 03

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).

Télécharger la présentation

General Computer Science for Engineers CISC 106 Lecture 03

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. General Computer Science for EngineersCISC 106Lecture 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 <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

  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 Contract %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;

  12. Write one for function ringArea.m • Contract • Description • Examples

  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. Conditions • If statement • Others (will talk about later)

  17. 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

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

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

  20. Condition operators • equals • == • not equals • ~= • greater than • > • >= • less than • < • <=

  21. 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);

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

More Related