Você está na página 1de 25

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,
one-dimensional 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: Laboratory Exercise No.: 1
Group No.: Section: CH51FC1
Group Members: ARAOJO, JOHN CARLO A. Date Performed: June 14, 2017

Date Submitted:
Instructor: Engr. Crispulo G. Maranan

6. Data and Results:


1.

Window Purpose

1.Command Window It is where you can type commands.

2.Figure Window It displays the graphic contents of MATLAB code

3.Editor Window It is a word processor for Matlab commands so it


automatically formats certain things for you such as
the command "for".

4.Help Window It displays the list of primary help topics in the


command window. It also provides access to various
help files.

5.Launch Pad Window It is a tool used to access all MATLAB services and
toolboxes

6.Command History It displays all previous command issues in a Matlab


session

7.Workspace Window It allow you to inspect variables in a spreadsheet-type


window

8.Current Directory to quickly access files on the MATLAB path

2.

Symbol Purpose

>> It shows you that the system is ready for input

; Signifies the end of the row

% Acts as a conversion specifier

clc It clears all input and output from the Command


Window display

3.

Mathematical Expression Result

>> 8 + 5/9 8.56

>> (8 + 5)/9 1.44

>> 8^5/9 3.64E+003

>>29^1/5 + 35^0.7 17.85

4.

Built-in Function Result

>>sqrt(144) 12

>>exp(7) 1.10E+003

>>abs(-99) 99

>>log(100000) 11.51

>>log10(100000) 5

>>factorial(10) 3628800

>>sin(pi/4) 0.71

>>round(19/6) 3

>>rem(16,5) 1

>>sign(-19) -1

5.

>>x= 10 x=10

>>x=4*x -15 x=25

>>a = 10 a=10

>>B= 9 B=9

>>C= (a B) +50 a/B *16 C=33.2222

>>a=10,B=9; C= (a B) +50 a/B *16 a=10

C= 33.2222

>>x = 0.99; x=
0.9900

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

6.

>>yr = [ 2001 2002 2003 2004


2005]

>>yr = [ 256; 299; 350; 402;


503]

>>y = [1:2:15]

>>y = [1.5:0.1;2.0]
>>y=[-5:15]

>>b = [21:-3:6]

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

>>b=linspace(30,10,11

c=

Columns 1 through 7
>>c=linspace(49.5,0.5)

49.5000 49.0051 48.5101 48.0152 47.5202 47.0253 46.5303

Columns 8 through 14

46.0354 45.5404 45.0455 44.5505 44.0556 43.5606 43.0657


Columns 15 through 21

42.5707 42.0758 41.5808 41.0859 40.5909 40.0960 39.6010

Columns 22 through 28

39.1061 38.6111 38.1162 37.6212 37.1263 36.6313 36.1364

Columns 29 through 35

35.6414 35.1465 34.6515 34.1566 33.6616 33.1667 32.6717

Columns 36 through 42

32.1768 31.6818 31.1869 30.6919 30.1970 29.7020 29.2071

Columns 43 through 49

28.7121 28.2172 27.7222 27.2273 26.7323 26.2374 25.7424

Columns 50 through 56

25.2475 24.7525 24.2576 23.7626 23.2677 22.7727 22.2778

Columns 57 through 63

21.7828 21.2879 20.7929 20.2980 19.8030 19.3081 18.8131

Columns 64 through 70

18.3182 17.8232 17.3283 16.8333 16.3384 15.8434 15.3485


Columns 71 through 77

14.8535 14.3586 13.8636 13.3687 12.8737 12.3788 11.8838

Columns 78 through 84

11.3889 10.8939 10.3990 9.9040 9.4091 8.9141 8.4192

Columns 85 through 91

7.9242 7.4293 6.9343 6.4394 5.9444 5.4495 4.9545

Columns 92 through 98

4.4596 3.9646 3.4697 2.9747 2.4798 1.9848 1.4899


Columns 99 through 100

0.9949 0.5000

7.

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

>>b = [23 56 78 73 68

35 98 54 32 15

99 34 23 12 2]

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

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

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

>>on=ones(3,4)

>>we=eye(5)

>>aa=[4 8 9]

>>bb= aa
>>B=[3 6 7 8; 8 7 6 4;2 7 9 3]

>>C=B

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

>>E=D(3)

>>D(2)=69

>>D(2) + D(5)

>>D(3)^3 + D(4)^4
>>M=[3 11 6 5;4 7 10 2;13 9 0 8]

>>M(2,3)=18

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

8.

>> v=[23 56 34 45 67 54 23 12 21]

>>w=v(2:6)

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

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

>>R=Q(:,3)
>>S=Q(2,:)

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

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

>>V=4:3:34

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

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

9.

Function Description Example

length(A) returns the length of obj. It is equivalent to the


command max(size(obj))

size(A) returns a row vector whose elements contain the


length of the corresponding dimension of A.
reshape(A,m,n) B = reshape(A,sz) reshapes A using the size
vector, sz, to define size(B)

diag(v) returns a square diagonal matrix with the


elements of vector v on the main diagonal.

Diag(A) returns a column vector of the main diagonal


elements of A.

where: A is a matrix and v is a vector

10.
>> b = Matlab Programming

>>c= My name is Richard Schooling

>>c(5)

>>c(12:18)

>>Info=char(Student Name:,Richard
Schooling,Grade:,A+)

11.

>>VecA=[ 8 6 7];VecB=[2 3 6];

>>VecC= VecA + VecB

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

>>C= A - B

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

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

>>C=A*B

>>D=B*A NONE

>>F=[6 7; 4 3]; G=[1 2; 4 5];

>>H=F*G

>>I=G*F

>>AV=[ 2 5 7];BV=[3;4;1];

>>AV*BV

>>BV*AV

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

>>b*A

>>A*b

>>D=5*A

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

>>B=inv(A)
>>A*B

>>A*A^-1

12.

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

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

>>X = A\B

>>Xb=inv(A)*B
>>C=[4 2 6;-2 8 10;6 2 3]

>>D=[8 4 0]

>>Xc=D/C

13.

>>A=[3 6 8; 3 5 6]

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

>>C=A.*B

>>D=A./B
>>E=B.^B

>>F=A*B F=

6 24 24

18 15 24

>>x=[1:8]

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

>>x=[1:2:15]

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

>>x=[0:pi/6:pi]

>>y=cos(x)
14.

Function Description Example

mean(A) returns the mean of the elements of A


along the first array dimension whose size
does not equal 1.

C=max(A) Describes the highest value in the matrix C= 5

(d,n)=max(A) d describes the maximum value in a >> A= [ 1 2 3 4 5; 5 4 3 2 1]


column
A=

1 2 3 4 5

5 4 3 2 1

>> [d,n]=max(A)

d=

5 4 3 4 5

n=

2 2 1 1 1

min(A) Minimum value in the matrix >> A=[1 2 3 4 5]

A=

1 2 3 4 5

>>min(A)

ans =

(d,n)=min(A) d describes the minimum value in a >> A= [ 1 2 3 4 5; 5 4 3 2 1]


column A=

n 1 2 3 4 5

5 4 3 2 1

>> [d,n]=min(A)

d=

1 2 3 2 1

n=

1 1 1 2 2

sum(A) Sums up all the values in a matrix >> A=[1 2 3 4 5]


depending on its column or row
A=

1 2 3 4 5

>> sum(A)

ans =

15

>> A= [ 1 2 3 4 5; 5 4 3 2 1]

A=

1 2 3 4 5

5 4 3 2 1

>> sum(A)

ans =

6 6 6 6 6

sort(A) sorts the elements of A in ascending >> A= [ 6 3 2 1 4 7]


order.
A=

6 3 2 1 4 7

>> sort(A)

ans =
1 2 3 4 6 7

median(A) returns the median value of A. >>A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]


A=

0 1 1
2 3 2
1 3 2
4 2 2
>>median(A)

ans:

1.5000 2.5000 2.0000

std(A) returns the standard deviation of the >>A = [4 -5 1; 2 3 5; -9 1 7];


elements of A along the first array >>std(A)
dimension whose size does not equal 1.
ans =

7.0000 4.1633 3.0551

det(A) returns the determinant of square matrix >>A = [1 -2 4; -5 2 0; 1 0 3]


A. A=

1 -2 4
-5 2 0
1 0 3

>>d = det(A)

ans =

-32

dot(a,b) returns the scalar product of A and B. >>A = [4 -1 2];


>>B = [2 -2 -1];

>>dot(A,B)

ans =

cross(a,b) returns the cross product of A and B >>A = [4 -2 1];


>>B = [1 -1 3];

>>cross(A,B)

ans =

-5 -11 -2

inv(A) computes the inverse of square matrix X. >>X = [1 0 2; -1 5 0; 0 3 -9]


X =

1 0 2
-1 5 0
0 3 -9

>>inv(X)

ans =

0.8824 -0.1176
0.1961
0.1765 0.1765
0.0392
0.0588 0.0588
-0.0980

7. Conclusion:
I therefore conclude that having the knowledge on MATLAB is a must have element for us engineers as
it has many useful applications especially in our field. Being knowledgeable on MATLAB will allow us to
perform engineering works a lot easier and faster.
In this activity, I was able to learn more about the different functions and commands being used in
MATLAB.
8. Problems;

9. Assessment (Rubric for Laboratory Performance):


TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

RUBRIC FOR LABORATORY PERFORMANCE

CRITERIA BEGINNER ACCEPTABLE PROFICIENT SCORE

1 2 3

I. Laboratory Skills

Manipulative
Members do not demonstrate Members occasionally Members always demonstrate
needed skills. demonstrate needed skills. needed skills.
Skills

Members are able to set-up


Members are unable to set-up Members are able to set-up
Experimental Set-up the material with minimum
the materials. the materials with supervision.
supervision.

Members occasionally
Member do not demonstrate Members always demonstrate
Process Skills demonstrate targeted process
targeted process skills. targeted process skills.
skills.

Members do not follow safety Members follow safety Members follow safety
Safety Precautions
precautions. precautions most of the time. precautions at all times.

II. Work Habits

Time Management / Members finish ahead of time


Members do not finish on time Members finish on time with
Conduct of with complete data and time
with incomplete data. incomplete data.
Experiment to revise data.

Members do not know their Members have defined Members are on tasks and
tasks and have no defined responsibilities most of the have defined responsibilities
Cooperative and
responsibilities. Group time. Group conflicts are at all times. Group conflicts
Teamwork
conflicts have to be settled by cooperatively managed most are cooperatively managed at
the teacher. of the time. all times.

Clean and orderly workplace Clean and orderly workplace


Neatness and Messy workplace during and
with occasional mess during at all times during and after
Orderliness after the experiment.
and after the experiment. the experiment.

Ability to do Members require supervision Members require occasional Members do not need to be
independent work by the teacher. supervision by the teacher. supervised by the teacher.

TOTAL SCORE
Other Comments / Observations:

TotalScore
RATING = ( 24 )x
100%

Evaluated by:

_______________________________________

Printed Name and Signature of Faculty Member Date: ___________________________