Mon. 9/10/07, Quiz #1, Questions and Responses

 

 

Q1. Problem Solving in Engineering and Science is composed of 5 steps. Complete the missing step below:

            1. State the Problem

            2. Describe the input and output

            3. Describe the algorithm to solve the problem

            4. Solve the problem

            5. ???

 

A1. The last step is to test or check out the results (the output) to see if they make sense. For instance, you want to find what the price per unit of a pizza pie is. The entire pizza is $9.99 and the resultant price per unit you found after step 4 is $15. This result obviously does not make sense! Price per unit can not be more than what the price of the entire pizza is!  You should go back and check out step 1 through 4.

 

Q2. Give one example for each of the following:

scalar value, vector, column vector, a 2x3 matrix

 

A2.

scalar: any single dimensional value . E.g.: 45, 60.

 

vector: is a 1xn matrix, where 1 is the number of rows, n is the number of columns. E.g.: [10  20 30]

 

column vector: is a nx1 matrix, where n is the number of rows, 1 is the number of columns.

E.g.:

10

20

30

 

a 2x3 matrix: has 2 rows and 3 columns.

Eg:

10         20         30

40         50         60

 

Q3. What does each of the following MATLAB commands do?

whos, save, load

 

A3.

whos: shows the information (name, type, size, attributes but not the value!) of the variables available in the current workspace.

 

save: saves the variables in the current workspace in to a file. The type of the file can be a .mat or .dat file. .mat file is a binary file, which is only recognized by the MATLAB. .dat file is an ASCII file (a text file), which can be opened or viewed by other programs or text editors.

To save variables in to a .mat file, you can use the MATLAB command:

 

save temp.mat  

 

This creates a temp.mat file with all the variables currently available in the workspace.

 

load: loads the variables from a .mat or .dat file into the current workspace.

 

For instance,

 

load temp.mat

 

Loads all the variables in the temp.mat file into the current workspace.

 

As an exercise and to understand save and load commands of MATLAB,  open a MATLAB session on Strauss.udel.edu in a SunRay machine or using SSH from a Windows PC or laptop, type the following commands in the MATLAB command prompt, and observe what happens (Note that, A and B are the variables created in your current workspace).

 

clear

clc

A = [1 2 3]

B = 66.7

whos

A

B

save temp.mat

clc

whos

A

B

load temp.mat

whos

A

B

 

 

Q4. What happens when we type the following at the MATLAB command prompt?

 

            >> B = [10, 20, 30; 40, 50, 60]

 

A4. A matrix B with 2 rows and 3 columns is created and echoed (printed) on the MATLAB command prompt. That is,

 

 

>> B = [10, 20, 30; 40, 50, 60]

 

B =

 

    10    20    30

    40    50    60

 

 

 

Q5. Give 2 examples of a Unix shell command   

 

A5. ls, cd, mkdir, pwd (check out chapter 1 and 2 of the Unix book to make yourself familiar with the some of the Unix shell commands that you will frequently use in the future!)