Lab 1, CISC106, Spring 2009

Goals

By the time you complete this lab, you should be able to:

  1. Log on to a Sun Ray terminal
  2. Start up both MATLAB and a web browser (Firefox)
  3. Type in basic commands into MATLAB and see their effect
  4. Save a sequence of MATLAB commands into a file (a so-called "dot-M" file)
  5. Run an existing .m file
  6. Write a new .m file
  7. Use the diary command to save your work into a file you can submit for grading
  8. Submit your saved work for grading using "Sakai"

You may get through this whole assignment in 50 minutes, but many people will finish and submit it later. Do as much as you can during the lab period, but in general you will finish labwork outside of lab.

Instructions

Here are some websites that you will find useful throughout this lab and in future labs:


and a very important one:

In addition, you should do the following steps:
  1. Go to the page http://www.udel.edu/network, log in, and access the option to change your Unix Default Group. Change your default group to the one that corresponds to CISC106.

  2. On that same page, access the option to change your Unix Default Shell. Change it to /bin/tcsh.

Step 1: Login to begin a SunRay session

Use the SunRay help site listed above. If you have login difficulties, check out the login help page FIRST; then ask your TA for help.

Ending a Sun Ray Terminal Session

  • Terminating a session will close all the open windows and stop all processing.
  • Need more help?

    Please consult the Troubleshooting section of GNOME Desktop for UD Sun Ray Terminals at the following link:

    http://www.udel.edu/topics/os/unix/sunray/aboutGnome.html#troubleshooting

    We are now ready to move to step two, which is starting up MATLAB and a web browser

    Step 2: Start up both MATLAB and a web browser (Firefox)

    So, from Step 1, you should be logged into a Sun Ray, and looking at the Gnome Desktop.

    Next, use the mouse to select the Applications Menu, and then the option Other, and finally MATLAB. Wait.

    You'll see the MATLAB splash screen. This should stay on the screen for a few seconds, and then be replaced by the MATLAB desktop, pictured after the splash screen. This is the same thing you saw at the beginning of lecture on Friday.

    If you already have Firefox open, skip the rest of this step. On the applications menu (the same one you used to start up MATLAB) you should find a menu item called "Internet", and under that, an item called "Web Browser" (or something like that). Select that option to start up Firefox. At the bottom of your screen, you'll see tabs that you can click on to move back and forth between the web browser and the MATLAB window.

    Enter the (temporary) address for the course web page: http://www.cis.udel.edu/~atlas/106/09Su/

    Then click on labs, then on lab01.html.

    You should then be looking at a copy of this page in the web browser. If not, ask your TA for assistance.

    Step 3: Type some expressions into MATLAB and see their effect

    The following exercises are designed to get you comfortable with the MATLAB environment. For now, we'll do all our work in the Command Window part of the MATLAB environment.

    First, let's calculate the value of 5 squared. Type it in and hit "return" (or "enter").

    >> 2^4

    You should get the following result:

     ans = 
    16

    Now, use MATLAB calculate the area of a circle of radius 3. Try typing this into the command window:

    >> area = pi * 4^2

    You should get the following result:

    
    area =
    
      50.2655
    
    >> 

    Now try typing the following:

    >> x = sin(pi/2);

    If you put the semicolon (;) on the end, then MATLAB will print nothing in response except the symbol >>, which is called the prompt. The prompt is where you type input into the MATLAB Command Window.

    But what you have done is to assign a value to a MATLAB variable called x. The value of x can be shown by evaluating x on the command line, like this:

    >> x

    The result should be something like this:

    
    x =
    
        1
    
    >> 

    Take a minute and play with the command window. "Playing" is a crucial part of learning about computer programs. Your lab is a great time to play because your TA can help you figure out anything you don't understand.

    Step 4: Write a MATLAB function into a file (a so-called "M-file" file)

    A sequence of MATLAB commands can be saved in a so called "M-file". An M-file is called an "M-file", because it has a name that ends in ".m", such as:

    To create a new .m file, choose "File"/"New"/"M-file". This will open a window where you can begin to type commands. Be patient—it may take several seconds for the new window to open!

    Into this window, type (approximately) the following. DON'T put your student id number---just your first and last name is sufficient!

    %Author: your name here, login name here, lab section, lab01, TA: your TA's name here
    %Description: calculates the area of a circle given the radius
    %Examples: circleArea(5) = 78.5
    % add another example
    % add another example
    function outputValue = circleArea(radius)
      outputValue = pi * radius ^ 2;
    		

    When  you are finished, use the Save As command from the File menu to save the file with the name circleArea.m

    think: As discussed in class, what two names must agree?

    think: What happens if the semi-colon is removed?

    Step 5: Test your function in the command window, as shown in class.

    Step 6: Use the diary command to save your work into a file you can submit for grading

    In the command window, type

    >> diary lab01.txt

    This turns on a record of what you type in MATLAB. Then type these three commands:

    >> type circleArea.m
    [a listing circleArea.m will appear here]
    >> circleArea(5)
    [the result of evaluating circleArea(5) will appear here]
    >> [now run several more examples]
    >> diary off
    

    Your text explains the diary command if you need further information. You should now have files in your account called circleArea.m and lab01.txt. In a later step, you will submit these two files for grading by your TA.

    Step 7: Write two more functions in M-files

    Now use your circleArea function to write the ringArea function that we wrote in class. Then, write two new functions: cylinderVolume (the volume of a cylinder is the area of the end * height) and pipeVolume (calculates the volume of material in the walls of a pipe). Be sure that your functions are written very simply in terms of other functions.

    When these three are complete, use the diary function to demonstrate all three while recording. This diary file and the M-files will also be submitted.

    Step 8: Submit your saved work using "Sakai".

    The following web site describes how to log on to MyCourses. Submitting to MyCourses will put a "time stamp" on your work so we know when you submitted it, but you will also submit a printed copy for grading.

    Note that although you can log on to Sakai from any web browser, in order to submit the work you do in MATLAB, you need to be on one of the SunRays on the UD campus so that you can get at the files lab01.m and lab01.txt

    Log onto Sakai (www.udel.edu/sakai) and find CISC106 (if it is not listed, tell your TA)

    Follow the instructions for submittingt an assignment in Sakai (help -> assignments -> submitting) and submit this as lab01). You should submit six files:

    1. four M-files that contain functions
    2. two diary files

    Now print the M-files and the diary files and staple them together. Make sure your name and section are on the front, and then submit to your TA. Why have both paper and electronic? The electronic is a time stamp and also cannot be lost; the paper version is easier to grade.

    Due Date

    Your lab is due two ways (unless your TA says otherwise). First, it is due electronically, submitted to Sakai, six days after your lab. For this lab, that means Sunday June 14th. Second, a paper copy of your lab is also due Monday June 15th. Your TA will decide how you will turn in the paper copy.

    You'll probably want to use a SunRay to access MATLAB. SunRay terminals are found in Pearson 101D, but that room is typically in use for various computer labs during the week. You can also find SunRay terminals in the basement of Smith Hall. In lecture, we'll talk about how you can also access MATLAB on "strauss.udel.edu" from any PC or Mac with Internet access. There will still be some features of MATLAB that you'll only be able to do on a SunRay, but most features you'll be able to do from anywhere.

    Adapted heavily from labs by Phill Conrad and Terry Harvey.

    End of lab01 for CISC106, Summer 2009