Sunteți pe pagina 1din 20

# Laboratory Exercise No.

1
Familiarization with Matlab Environment, Built-in Functions, Matrices and Plotting
1. Objective(s):
The activity aims to familiarize the students with matlab environment, built-in functions, matrices and
plotting.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 get acquainted with matlab environment and its various features.
2.2 understand the built-in functions of matlab.
2.3 Operate on the matrices.
2.4 Plot different graphs using matlab.
3. Discussion:
Matlab is a powerful language for technical computing. Its basic data element is matrix (array).It
can be used for math computations, modeling and simulations, data analysis and processing, visualization
and graphics, and algorithm development.
The standard Matlab program has tools (functions) that can be used to solve common problems.
The array is a fundamental form that Matlab uses to store and manipulate data. An array is a list of
numbers arrange in rows or in columns. The simplest array (one-dimensional) is a row, or a column of
numbers. A more complex array (two-dimensional) is a collection of numbers arranged in rows and
columns. One use of array is to store information and data, as in a table. In science and engineering, onedimensional arrays frequently represent vectors and two-dimensional arrays represent matrices.
Once variables are created in Matlab they can be used in a wide variety of mathematical
operations. Matlab is designed to carry out advanced array operations that have many applications in
science and engineering. Addition and subtraction are simple operations. The other basic operations,
multiplication, division and exponentiation can be done in Matlab in two different ways. One way, which
uses the standard symbols (*,/ and ^), follows the rules of linear algebra. The second way, which is called
element-by-element operations, uses the symbols .*,./ and .^ ( a period is typed in front of the standard
operation symbol).In both types of calculations, Matlab has left division operator (.\ or \).
4. Resources:
Matlab
5. Procedure:
1.Identify the different matlab windows and write its corresponding purpose.
2.Note the different symbols used in the command window and write its corresponding use.

3.Use matlab as a calculator and show the results in the accompanying table.
4.Note the different built-in functions and show the results in the accompanying table.
5.Evaluate the results after pressing the enter key for the assignment operator (=).
6.Evaluate the results after pressing the enter key for the creation of vectors (row vector and column vector)
from a known list of numbers, with constant spacing by specifying the first term, the spacing, and the last
term, with constant spacing by specifying the first and last terms,and the number of terms
7.Evaluate the results after pressing the enter key for the creation of two-dimensional array (matrix).
8.Evaluate the results after pressing the enter key using colon (:) in addressing arrays.
9. Identify the different built-in functions for handling array and indicate its description and give an example.
10.Evaluate the results after pressing the enter key that involves strings and strings as variables.
11. Evaluate the results after pressing the enter key that involves the operations of matrices.
12.Evaluate the values of x, y and z of the three equations three unknowns :
4x 2y + 6z = 8
2x + 8y + 2z = 4
6x + 10y + 3z = 0
13.Evaluate the results after pressing the enter key that involves element-element operations.
14.Identify the different built-in functions for analyzing arrays and indicate its description and give an
example.

Course:
Group No.:
Group Members:

Section:
Date Performed:
Date Submitted:
Instructor:

1.
Window

Purpose

1.Command Window

## The Command window is used to execute

commands or aliases directly in the Visual Studio
integrated development environment (IDE).

2.Figure Window

## Figures are windows that contain graphics or user

interface components.

3.Editor Window

## The window where you edit m- files

4.Help Window
6.Command History
7.Workspace Window
8.Current Directory

2.
Symbol

Purpose

>>
;
%
clc
3.
Mathematical Expression

Result

>> 8 + 5/12

8.42

>> (8 + 5)/12

1.08

>> 8^5/12

2.73E+003

>>29^1/5 + 35^0.12

7.33

4.
Built-in Function

Result

>>sqrt(112)

10.58

>>exp(12)

1.63E+005

>>abs(-12)

12

>>log(112000)

11.63

>>log10(112000)

5.05

>>factorial(12)

479001600

>>sin(pi/12)

0.26

>>round(19/12)

>>rem(16,12)

>>sign(-12)

-1

5.
>>x= 12

12

>>x=4*x -12

36

>>a = 12

12

>>B= 6

32

C =32

>>x = 0.99;

x = 0.99

## >>E = sin(x)^3 + cos(x)^4

E =0.6750

6.
>>yr = [ 2012 2013 2014 2015 2016]

yr =
Columns 1 through 4

2012

2013

2014

2015

Column 5
2016
>>yr = [ 255; 259; 612; 312; 912]

Yr =
255
259
612
312
912

>>y = [1:2:16]

y= 1

>>y = [1.78:0.1;2.0]

y =2

>>y=[-5:17]

y=

9 11 13 15

Columns 1 through 9
-5 -4 -3 -2 -1

Columns 10 through 18
4

9 10 11 12

Columns 19 through 23
13 14 15 16 17
>>b = [34:-3:6]

B=
Columns 1 through 9
34 31 28 25 22 19 16 13 10
Column 10
7

>>a = linspace(0,8,9)

a= 0

>>b=linspace(10,9,8)

b=

Columns 1 through 5

## 10.0000 9.8571 9.7143 9.5714 9.4286

Columns 6 through 8
9.2857 9.1429 9.0000
>>c=linspace(19.5,0.5)

c=
Columns 1 through 5
19.5000 19.3081 19.1162 18.9242 18.7323
Columns 6 through 10
18.5404 18.3485 18.1566 17.9646 17.7727
Columns 11 through 15
17.5808 17.3889 17.1970 17.0051 16.8131
Columns 16 through 20
16.6212 16.4293 16.2374 16.0455 15.8535
Columns 21 through 25
15.6616 15.4697 15.2778 15.0859 14.8939
Columns 26 through 30
14.7020 14.5101 14.3182 14.1263 13.9343
Columns 31 through 35
13.7424 13.5505 13.3586 13.1667 12.9747
Columns 36 through 40
12.7828 12.5909 12.3990 12.2071 12.0152
Columns 41 through 45
11.8232 11.6313 11.4394 11.2475 11.0556
Columns 46 through 50
10.8636 10.6717 10.4798 10.2879 10.0960
Columns 51 through 55
9.9040 9.7121 9.5202 9.3283 9.1364

Columns 56 through 60
8.9444 8.7525 8.5606 8.3687 8.1768
Columns 61 through 65
7.9848 7.7929 7.6010 7.4091 7.2172
Columns 66 through 70
7.0253 6.8333 6.6414 6.4495 6.2576
Columns 71 through 75
6.0657 5.8737 5.6818 5.4899 5.2980
Columns 76 through 80
5.1061 4.9141 4.7222 4.5303 4.3384
Columns 81 through 85
4.1465 3.9545 3.7626 3.5707 3.3788
Columns 86 through 90
3.1869 2.9949 2.8030 2.6111 2.4192
Columns 91 through 95
2.2273 2.0354 1.8434 1.6515 1.4596
Columns 96 through 100
1.2677 1.0758 0.8838 0.6919 0.5000

7.
>>a = [2 35 6;5 67 88;22 56 89]

a=
2 35

5 67 88
22 56 89
>>b = [25 06 88 73 68;35 98 54 32 15

b=

;99 34 23 12 2]
25

6 88 73 68

35 98 54 32 15
99 34 23 12

>>cd = 9 ;e 7;h=8;

Ram =

>>Ram=[e, cd*h,cos(pi/3);h^2,sqrt(h*h/cd),15]

## 7.0000 72.0000 0.5000

64.0000 2.6667 15.0000

>>Z= [1:2:11;0.0:5:25;linspace(10,60,6)]

Z=
1

9 11

5 10 15 20 25

10 20 30 40 50 60
>>zr=zeros(3,5)

>>on=ones(4,2)

>>we=eye(3)

zr =
0

on =
1

we =
1

>>aa=[4 8 12]

aa = 4

>>bb= aa/

bb =

8 12

4
8
12
>>B=[3 6 7 8; 8 7 6 4;2 7 9 3]
>>C=B

B=
3

C=

>>D=[ 3 5 6 8 23 67]

D=3

8 23 67

>>E=D(3)

E=6

>>D(2)=67

D = 3 67

8 23 67

>>D(2) + D(5)

ans =90

>>D(3)^3 + D(4)^4

Ans = 4312

## >>M=[3 11 6 5;4 7 10 2;13 9 0 8]

M=
3 11

>>M(2,3)=12

>>M(3,2)-M(2,1)

7 10

13

3 11

7 12

13

M=

ans = 5

8.
>> v=[25 56 39 45 67 54 23 12 21]

V = 25 56 39 45 67 54 23 12 21

>>w=v(2:6)

w = 56 39 45 67 54

>>Q=[1 3 4 5 6 8 ;4 6 7 8 2 1;1 1 4 6 8 9;

Q=

23 56 7 8 34 2; 21 45 67 83 2 3]

23 56

8 34

21 45 67 83
>>R=Q(:,3)

R=
4
7
4
7
67

>>S=Q(1,:)

S= 1

>>T=Q(1:2,:)

T=

>>U=Q(1:3,2:4)

>>V=5:3:34

U=

V=

Columns 1 through 9
5

8 11 14 17 20 23 26 29

Column 10
32
>>A=[10:-1:4;ones(1,7);2:2:14;zeros(1,7)]

>>B=A([1,3],[1,3,5:7])

A=
10

8 10 12 14

10

6 10 12 14

B=

9.
Function

Description

Example

length(A)
size(A)
reshape(A,m,n)
diag(v)
Diag(A)
where: A is a matrix and v is a vector

10.
>> b = 'Matlab Programming'

c = Matlab Programming

## c = My name is Roxette Malicdem

>>c(5)

Ans = a

>>c(12:18)

Ans = Roxette

>>Info=char(Student

Name:,Roxette Info =
Student Name:
A+

11.
>>VecA=[ 9 6 7];VecB=[1 3 6];

VecC = 10

9 13

## >>VecC= VecA + VecB

>>A=[3 -5 7;7 8 3];B=[2 4 5; 1 2 2];

C=

>>C= A - B

>>D= A + B

1 -9

D=
5 -1 12
8 10

>>A=[2 3 4; 5 4 7; 3 6 9; 5 3 1];

C=

>>B=[3 4 ; 3 2 ; 7 8];

43 46

>>C=A*B

76 84
90 96
31 34

>>D=A*B

D=
43 46
76 84
90 96
31 34

## >>F=[8 7; 4 3]; G=[19 2; 4 5];

>>H=F*G

H=
180 51
88 23

>>I=G*F

I=

160 139
52 43
>>AV=[ 2 5 7];BV=[3;4;1];

ans = 33

>>AV*BV
>>BV*AV

ans =
6 15 21
8 20 28
2

>>b*A

ans =
4 12 14 18
6

>>A*b

8 12

ans =
4 12 14 18
6

>>D=1*A

## >>A=[3 -2 5; 3 2 6;7 4 2];

>>B=inv(A)

8 12

D=
2

B=
0.1408 -0.1690 0.1549
-0.2535 0.2042 0.0211
0.0141 0.1831 -0.0845

>>A*B

ans =

-0.0000 1.0000

## -0.0000 0.0000 1.0000

>>A*A^-1

ans =
1.0000 0.0000 0.0000
-0.0000 1.0000

## -0.0000 0.0000 1.0000

12.
>>A = [3 -2 6;2 8 2;6 10 3];

X=

>>B= [8;4;0];

-1.7619

>>X = A\B

0.3571
2.3333

>>Xb=inv(A)*B

Xb =
-1.7619
0.3571
2.3333

## >>C=[4 2 6;-2 8 10;6 2 3]

>>D=[8 4 0]

C=
4

-2

8 10

D=
8

>>Xc=D/C

Xc =
-1.8049 0.2927 2.6341

13.
>>A=[2 6 8; 3 5 6]

A=

>>B=[2 4 3; 6 3 4]

>>C=A.*B

B=

C=
4 24 24
18 15 24

>>D=A./B

D=
1.0000 1.5000 2.6667
0.5000 1.6667 1.5000

>>E=B.^B

E=
4

256

46656
>>F=A/B

27

27

256

F=
1.9873 -0.1564
1.3362 0.1459

>>x=[1:8]

x=
1

>>y=x.^2 + 5*x

y=
6 14 24 36 50 66 84 104

>>x=[1:2:15]

x=
1

## >>y=(x.^3 + 5*x)./(4*x.^2 10)

9 11 13 15

y=

Columns 1 through 4

42

150

378

Columns 5 through 8
774
>>x=[0:pi/6:pi]

1386

2262

3450

x=

Columns 1 through 5

## 0 0.5236 1.0472 1.5708 2.0944

Columns 6 through 7

2.6180 3.1416
>>y=cos(x)

y=

Columns 1 through 5

## 1.0000 0.8660 0.5000 0.0000 -0.5000

Columns 6 through 7

-0.8660 -1.0000
14.
Function
mean(A)
C=max(A)
(d,n)=max(A)

Description

Example

min(A)
(d,n)=min(A)
sum(A)
sort(A)
median(A)
std(A)
det(A)
dot(a,b)
cross(a,b)
inv(A)

7. Conclusion:
8. Problems;

## TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

RUBRIC FOR LABORATORY PERFORMANCE

CRITERIA

BEGINNER

ACCEPTABLE

PROFICIENT

## Members do not demonstrate

needed skills.

Members
occasionally
demonstrate needed skills.

## Members always demonstrate

needed skills.

Experimental Set-up

the materials.

## Members are able to set-up

the materials with supervision.

## Members are able to set-up

the material with minimum
supervision.

Process Skills

## Member do not demonstrate

targeted process skills.

Members
occasionally
demonstrate targeted process
skills.

## Members always demonstrate

targeted process skills.

Safety Precautions

## Members do not follow safety

precautions.

Members
follow
safety
precautions most of the time.

Members
follow
safety
precautions at all times.

Time Management /
Conduct
of
Experiment

## Members do not finish on time

with incomplete data.

incomplete data.

## Members finish ahead of time

with complete data and time to
revise data.

Cooperative
Teamwork

and

## Members do not know their

responsibilities.
Group
conflicts have to be settled by
the teacher.

Members
have
defined
responsibilities most of the
time.
Group conflicts are
cooperatively managed most
of the time.

## Members are on tasks and

have defined responsibilities at
all times. Group conflicts are
cooperatively managed at all
times.

Neatness
Orderliness

and

## Messy workplace during and

after the experiment.

## Clean and orderly workplace

with occasional mess during
and after the experiment.

## Clean and orderly workplace at

all times during and after the
experiment.

Ability
to
do
independent work

by the teacher.

## Members require occasional

supervision by the teacher.

## Members do not need to be

supervised by the teacher.

I. Laboratory Skills
Manipulative
Skills

TOTAL SCORE

RATING
100%

Evaluated by:

TotalScore
24
(
)x

SCORE

## Printed Name and Signature of Faculty Member

Date: ___________________________