Você está na página 1de 3

About MATLab

Parts of MATLab
*Workspace Window - list of variables
*Command History - history of all the commands
Operations:
".* " --> Element-wise multiplication. (Una si dot.)
"v'" --> Transpose
*Be careful with vector multiplication!
Commands:
Size(C) = know the row x columns.
m=1:5 = Default increment 1.
n=1:0.2:5 = Increment sa gitna.
linspace (0,10,6) - from 1 to 10, but six values
Logspace (1,3,3) - from 1 to 3, but three values
Checking Keyword and Varname: iskeyword, isvarname x (returns 0 or 1), which (to check if the name is built in)
Plot Function:
1. Select a range x.
2. Select a range y.
3. Plot (x,y)
4. Title ('My Graph')
5. Xlabel ('Independent Variable')
6. Ylabel ('Dependent Variable
MatLab - Matrix Laboratory

MATH 014 Page 1

Answers to Exercise 3

1. Assign to the variable x1 the value in the second column of matrix a. This is sometimes represented in mathematics textbooks
as elements a1,2 and could be expressed as x1=a1,2.
a. x1=a(2)
2. Assign to the variable x2 the third column of matrix b.
a. x2=b(:,3)
3. Assign to the variable x3 the third row of matrix b.
a. x3=b(3,:)
4. Assign to the variable x4 the values in matrix b along the diagonal.
a. x4=[b(1) b(5) b(9)]
5. Assign to the variable x5 the first three values in matrix a as the first row and all the values in matrix b as the second th rough
the fourth row.
a. x5=[a(1:3);b]
6. Assign to the variable x6 the values in matrix c as the first column, the values in matrix b as columns 2,3 and 4 and the val ues
in matrix a as the last row.
a. x6=[c,b;a]
7. Assign to the variable x7 the value of element 8 in matrix b, using the single-index-number identification scheme.
a. x7=b(4)
8. Convert matrix b to a column vector named x8.
a. x8=b(1:9)

Part III:
1. Create a 3 x 3 matrix of zeros.
a. a=zeros(3)
2. Create a 3 x 4 matrix of zeros.
a. b=zeros(3,4)
3. Create a 3 x 3 matrix of ones.
a. c=ones(3)
4. Create a 5 x 3 matrix of ones
a. d=ones(5,3).
5. Create a 4 x 6 matrix in which all the elements have a value of pi.
a. e=pi*ones(4,6)
6. Use the diag function to create a matrix whose diagonal has values of 1, 2, 3.
a. f=diag([1,2,3])
7. Create a 10 x 10 magic matrix.
g=magic(10)
a. Extract the diagonal from this matrix.
diag(g)
b. Extract the diagonal that runs from lower left to upper right from this matrix.
Diag(flipud(g))
c. Confirm that the sums of the rows, columns, and diagonals are all the same.
Sum(g)

MATH 014 Page 2

User Defined Functions (MATLab)


*Created functions must be on the same file location.
*It isn't always necessary to define an output.
*To create a function:
Function output = poly (x)

*Multiple Inputs

*Multiple Outputs

MATH 014 Page 3

Você também pode gostar