Professional Documents
Culture Documents
2. Instructions:
You should perform the Lab on an individual basis. You may, however, seek assistance
from TAs when you cant figure things out. To do so just raise your hand and a TA will
assist you.
Passing the Lab will require that you answer all the questions in the Tasks and Exercise
sections .
Then, use the third iskeyword command to familiarize yourself with other protected
keywords. Finally, attempt the following:
while = 3
Note the error message, so you can identify this problem in the future. Notice how
while turns blue once you type it, this indicates that it is a keyword that MATLAB
recognizes.
4. Number Format
MATLAB uses its own code to compute its operations; however, the results can be
displayed on the Command Window or in a script file in different formats using
MATLABs built-in function format. It is important to remember that the format
command is only used to format the output of a calculation. For more information about
this command, type: help format in the MATLAB Command Window.
Task 2(a):
Objective: Evaluate the expression e-2ln(5) and express the result in the formats available
in MATLAB. To do this, follow these instructions:
>> format short % changing the output format to short
>> a=exp(-2)
a =
0.1353
>> b = log(5)
b =
1.6094
>> a*b
ans =
0.2178
>>format long %changing the format to long
>> a*b
ans =
0.21781373573101
Task 2(b):
Type: help format on the MATLAB Command Window and choose 8 formats among the
list. Introduce the following matrix into MATLAB and display it in those formats.
A = [e-20
ln(10)
e2]
6. Matrix Operations
MATLAB is capable of doing element by element mathematical operations as well as
standard matrix operations (determinants, inversion, dot products, etc.). There are also
built-in MATLAB functions to retrieve specific elements from a matrix as well as to
determine the size of a matrix.
Task 4:
Perform the following commands to familiarize yourself with matrix operations.
>> A = [1 2; 3 4];
>> B = [1 3; 2 6];
>> C= [8 9];
Once you have defined matrices A, B and C try the following operations.
>>A+B
>>A+C
>> A.*B
>>A*B
>>C.^2
>>C^2
>>inv(A)
>>A
>>det(B)
>>size(A)
>>A(1,2)
What is the difference between A*B and A.*B? The first command performs a row-bycolumn multiplication while the second one performs an element by element
multiplication. It is very important to understand the difference between these two
operations!
8. Exercises
1. You create the following array:
t = 0:0.5:8
Using linspace command, what will you do to obtain the same result?
2. Given the following matrices, perform the operations requested below and express it
in short format:
A=[2 3 8; 6 8 12; 5 6 12]
B=[9 14 -6; 8 24 5; 11 6 5]
C=[24, 23, 3; 5 9 8; 6 -3 15]
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
14A+9B-3C+15*B*(A*2C)
Inverse of A + Inverse of C + Transpose of (Transpose of B)
Transpose of C + Inverse of (B*A)
(Determinant of (Transpose of(Inverse of (Transpose of A))))^2
Determinant of A + (Determinant of (Transpose of B))^2
A*(Inverse of (B*C))
B*((Transpose of B)*B)
C*((Inverse of C)^(-1))+A*(Transpose of A)
3A+2sin(pi/2)B-exp(-9)*C
Inverse of (A*(Transpose of (B))+Transpose of C 15*(B*C)
Hint: the angles are expressed in radians and perform matrix operations, not element by
element operations.
3. Generate a script file to calculate the surface area and volume of a rectangular pyramid
with height of 0.5 m that prompts for dimensional user inputs. Test your script file for the
following cases:
a) Base is a square with side length=8 cm
b) Base is rectangular with length= 24 cm, width=5 cm
Formulas to be used:
LW h
P h
S P = B + L BW B ; V P = b b
3
2
4. The behavior of a non-ideal gas can be represented by the following Van der Waals
equation of state (EOS):
RT
a
P=
2
V b V
Where,
a = 9.2548e6;
b = 90.3393;
R = 82.06;
(cm3.atm/mol2)
(cm3/mol)
(cm3.atm/mol.K)
Create a script that calculates the pressure from the above EOS using the
following data:
Volume (cm3/mole)
1000
1500
2000
2500
3000
Temperature (K)
250
300
350
400
450