

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: Introduction to Computing Using MATLAB; Subject: Computer Science; University: Cornell University; Term: Fall 2008;
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CS1112 Section (Lab) 1
When you have completed the lab, show this sheet and any associated programs to your lab instructor, who will record that you have completed the lab. If you do not finish this exercise during the lab, show the instructor what you have done at the end of the lab and be sure to complete it in the next few days.
If you have any questions, ask your lab instructor or a consultant immediately! They are in the lab to help you learn the material.
Matlab provides numerous built-in variables and functions. For each line below, type the text in the Command Window and press
% This is a comment--no action is executed by the computer
% From this point on, read but do not type the text after the % symbol in a line.
% Variables, constants, and simple calculations: a= 100 % Look at the Workspace Pane: a VARIABLE called a has been created b= 99 % Look at the Workspace Pane: a VARIABLE called b has been created format compact a/b % _____________________________ ans y= ans % _____________________________ format long y format short y p=(32)^ q=(32)^2; % Did you type the semi-colon? Look at the Workspace Pane: q is % created but its value is not shown in the Command Window.
x = 2; y = x^x; z = y^y % _____________________________ format loose
% Built-in functions: sqrt(x) pi % a built-in variable cos(pi) % _____________________________ abs(ans) abs(cos(pi)) % _____________________________ exp(ans) rem(5,2) % What does function rem do? If you’re not sure, try a few more % examples: rem(9,7), rem(10,6), ... ___________________________ rand(1) % Generate one random number in the range of (0,1) help rand lookfor magic % MATLAB searches its documentation for the keyword ’magic’ % Wait a few seconds. If this command takes too long to % complete, press
Download the file spiral.m from the Exercises page to the Desktop of your computer. (You can use another directory/path, but be sure to write down the location of your file.)
Now set the Current Directory to be the directory in which you have stored your file spiral.m. You should now see the file listed in the Current Directory Pane.
To run the program (script) spiral, in the Command Window type the file name without the extension .m. What do you see on the screen?
To read the program, open the program file in the Editor Window: select menu options File→Open and then select or type the file name spiral.m. (Or in the Current Directory Pane double click on the file name.)
Now experiment with the program!
A temperature can be converted from the Fahrenheit scale to Celsius using the formula c = 59 (f − 32) where f is a temperature given in ◦F and c is the resulting temperature in ◦C. Write a script to prompt the user for a temperature in ◦F and convert and print the temperature in ◦C. Save the file as convertF2C.m.
Answer the following questions:
You will use CMS to access the online book chapters, submit homework, find your scores, and view grading comments. If you enrolled in CS1112 before 4pm on 8/28, you can use CMS already. Try to log on CMS now. If you cannot log on, ask your section instructor to add your information into CMS. Note that your homework must be submitted through CMS.
Please delete your files from the computer before you leave!