LabExercise 1 - Familiarization With MATLAB
LabExercise 1 - Familiarization With MATLAB
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.
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:ChE 508 Laboratory Exercise No.:1
Group No.: Section:CH51FC1
Group Members: Percil, Queenie Rose I. Date Performed:06/14/17
Date Submitted:06/14/17
Instructor: Engr. Crispulo Maranan
Window Purpose
1. Command Window It is where you enter commands at the command line,
indicated by the prompt
2. Figure Window It is where you can plot a function.
3. Editor Window It is where you can write a program or script called the
m-file
4. Help Window It is where you can read the instructions on how to use
the matlab.
5. Launch Pad Window To access all M ATLAB services and toolboxes
6. Command History It displays all commands issued in M ATLAB since the
last session
7. Workspace Window To view variable definitions and variable memory
allocations
8. Current Directory to quickly access files on the M ATLAB path.
2.
Symbol Purpose
>> It is where you can type the opereator
; Use semicolons to separate rows in an array creation
command, or to suppress the output display of a line
of code.
% he percent sign is most commonly used to indicate
nonexecutable text within the body of a program. This
text is normally used to include comments in your
code.
clc This clears your workspace, closes all figures, and
clears command window. clr is a quick way to "reset"
M atlab.
3.
Mathematical Expression Result
>> 8 + 5/9
>> (8 + 5)/9
>> 8^5/9
>>29^1/5 + 35^0.7
4.
>>sqrt(144)
>>exp(7)
>>abs(-99)
>>log(100000)
>>log10(100000)
>>factorial(10)
>>sin(pi/4)
>>round(19/6)
>>rem(16,5)
>>sign(-19)
5.
>>x= 10
>>x=4*x -15
>>a = 10
>>B= 9
>>x = 0.99;
6.
>>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=linspace(49.5,0.5)
7.
>>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(2,3)=18
>>M(3,2)-M(4,1)
8.
>>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) The statement length(X) is equivalent x = ones(1,8);
to max(size(X)) for nonempty arrays n = length(x)
and 0 for empty arrays.
n =
n = length(X) returns the size of the 8
longest dimension of X. If X is a x = rand(2,10,3);
vector, this is the same as its length. n = length(x)
n =
10
size(A) returns the sizes of each dimension of m = size(rand(2,3,4),2)
array X in a vector d with ndims(X)
elements. m =
3
reshape(A,m,n) The reshape function returns a new
array with n rows and m columns (n*m
must equal the number of elements in
the original array). The new array has
the same elements as the original.
>>c(5)
>>c(12:18)
>>Info=char(‘Student Name:’,’Richard
Schooling’,’Grade:’,’A+’)
11.
>>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
>>I=G*F
>>AV=[ 2 5 7];BV=[3;4;1];
>>AV*BV
>>BV*AV
>>A*b
>>D=5*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
>>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
>>x=[1:8]
>>y=x.^2 + 5*x
>>x=[1:2:15]
>>x=[0:pi/6:pi]
>>y=cos(x)
14.
Function Description Example
mean(A) mean(A) returns the mean of the
elements of A along the first array
dimension whose size does not
equal 1.
8. Problems;
9. Assessment (Rubric for Laboratory Performance):
1 2 3
I. Laboratory Skills
Ability to do Members require superv ision Members require occasional Members do not need to be
independent w ork by the teacher. superv ision by the teacher. superv ised by the teacher.
TOTAL SCORE
Other Comments / Observations:
RATING = ( ) x 100%
Evaluated by:
_______________________________________