CS10-8L: Computer Programming Laboratory
Machine Problem #1: Getting Started
OBJECTIVES
To familiarize the students in Matlab interface.
To enable the students to use some basic commands.
GRADING SYSTEM
From (%) To (%) Grade
0.00 64.99 5.00
65.00 68.89 3.00
68.9 72.89 2.75
72.9 76.79 2.50
76.8 80.69 2.25
80.7 84.59 2.00
84.6 88.49 1.75
88.5 92.39 1.50
92.4 96.29 1.25
96.3 100.00 1.00
INSTRUCTIONS
A. Opening and closing Matlab.
1. To open Matlab, double click the desktop icon or search and click in the programs.
2. To exit Matlab, either click on Exit Matlab from the File menu or typing quit or exit in the Command
Prompt Window. DO NOT click on the close box on the upper right corner.
B. Accessing the Help window.
1. To get in the Help browser, either click on the help button (?) in the desktop toolbar, or select the Help
menu in any tool.
2. Once in the Help browser, select the Contents tab in the Help Navigator pane on the left.
3. To get to the desktop section, expand MATLAB > Getting Started > Development Environment.
C. Using the Command window.
1. Type the following in the Command window, then click Enter:
>> 2+3 <Enter>
>> 3-2 <Enter>
>> 2*3 <Enter>
>> 1/2 <Enter>
>> 2^3 <Enter>
>> 2\1 <Enter>
2. Also try the following commands:
>> 2 .*3 <Enter>
>> 1 ./ 2 <Enter>
Prepared by: Geldof Resuello
Prepared date: February 2020
>> 2 .^3 <Enter>
3. Matlab has a useful editing feature called smart recall. Just type the first few characters of the
command you want to recall, say 2*, then press the up-arrow key. This would recall the most recent
command starting with 2*.
4. Try the following commands:
>> 0/1 <Enter>
>> 1/0 <Enter>
>> 0/0 <Enter>
Matlab will try to warn you in case you didn’t realize you were dividing by zero but will still give you the
answer Inf. In the last command, another special value is obtained NaN, which means Not-a-Number.
5. To assign variables, perform the following commands:
>> x = 2 <Enter>
>> y = 3; z = 4; <Enter>
>> w = x + y - z <Enter>
E. Browsing the Command History window.
1. You can run a command again by simply double clicking on it. Double click on w = x + y – z
2. To alter the command before running it, click and drag the command to the Command window, change
it, and then hit enter. Drag w = x + y – z then change it to w = x + y + z.
F. Familiarizing with other tools.
1. To change the file location you are working on, click on the Current Directory tab and type or browse
to the correct address.
2. The Directory shows the files in the current directory. The files can be run by double clicking and
dragging them into the Command window.
3. The Workspace keeps track of the variables that are created. Double click on x and change the value
to 4.
Prepared by: Geldof Resuello
Prepared date: February 2020
MACHINE PROBLEM
Answer the following problems using commands in Matlab. Make sure to indicate the commands in your
submission, as specified in the Answer Sheet. Important: Only upload the Answer Sheet (i.e. exclude the
Instructions part). Check the deadline indicated in Blackboard. Failure to submit on time will incur an
automatic grade of 0 while failure to follow instructions will incur deductions.
1. Compute the following using the correct order of operations:
a. 2−4∗(5 3−2+2∗( 5+6 ))
4∗5 3−2
b. 2−
2∗(5+6)
4∗53−2
2−
c. 2
+6
5
2. Compute for the volume of a truncated pyramid with a = 5, b = 3 and h = 10, given the formula:
1
V = ( a2 +ab+ b2 ) h
3
Prepared by: Geldof Resuello
Prepared date: February 2020
IT131-8L Machine Problem Answer Sheet
Machine
1 (Getting Started) Score
Problem #
Name Section
1.
a. Answer:
Command:
b. Answer:
Command:
c. Answer:
Command:
2. Answer:
Command:
Prepared by: Geldof Resuello
Prepared date: February 2020