0% found this document useful (0 votes)
63 views

Machine Problem 1

This document provides instructions for students on an introductory Matlab exercise. It outlines objectives to familiarize students with the Matlab interface and basic commands. It then provides detailed instructions on opening and closing Matlab, accessing help, using the command window, command history, and other tools. It includes sample problems for students to practice basic math operations and assigning variables in Matlab.

Uploaded by

angelo hijalga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Machine Problem 1

This document provides instructions for students on an introductory Matlab exercise. It outlines objectives to familiarize students with the Matlab interface and basic commands. It then provides detailed instructions on opening and closing Matlab, accessing help, using the command window, command history, and other tools. It includes sample problems for students to practice basic math operations and assigning variables in Matlab.

Uploaded by

angelo hijalga
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS10-7L: Computer Programming Laboratory

Exercise #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>
>> 2 .^3 <Enter>

Prepared by: Engr. Cheryl Mari M. Isip


CS10-7L: Computer Programming Laboratory
Exercise #1: Getting Started

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.

MACHINE PROBLEM
Answer the following problems using commands in Matlab. Make sure to indicate your commands
in your submission and,
1. Compute the following using the correct order of operations:
a. 2 − 4 ∗ (53−2 + 2 ∗ (5 + 6))
4∗53−2
b. 2 −
2∗(5+6)
4∗53−2
c. 2 − 2
+6
5
2. Compute for the volume of a truncated pyramid with a = 5, b = 3 and h = 10, given the
formula:
1
𝑉 = (𝑎2 + 𝑎𝑏 + 𝑏 2 )ℎ
3

Prepared by: Engr. Cheryl Mari M. Isip


CS10-7L: Computer Programming Laboratory
Exercise #1: Getting Started

ANSWERS
1.
a. Answer: -106
Command:
>> 2-4*(5^(3-2)+2*(5+6))

b. Answer: 1.0909
Command:
>> 2-(4*5^(3-2))/(2*(5+6))

c. Answer: -1.1250
Command:
>> 2-(4*5^(3-2))/(2/5+6)

2. Answer: 163.3333
Command:
>> a = 5; b = 3; h = 10
>> V=1/3*((a^2)+(a*b)+(b^2))*h

Prepared by: Engr. Cheryl Mari M. Isip

You might also like