By the time you complete this lab, you should be able to:
.m
file.m
filediary
command to save your work into a file you can submit for grading 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.
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.
Applications
>
Logout
menu item.
Do not
select the "Save Current Setup" choice in the logout
dialog box. 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
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.
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.
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.
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:
plotResults.m
calculateAnswer.m
labReport.m
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?
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.
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.
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:
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.
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.