0% found this document useful (0 votes)
28 views4 pages

23MAT107 Calculus Lab1

Uploaded by

Abhinav p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

23MAT107 Calculus Lab1

Uploaded by

Abhinav p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Amrita School of Engineering, Bengluru-35

23MAT107
Calculus
Lab Practice Sheet-1
Creation of vectors, matrices, vector operations and matrix operations
➢ Go to Octave online / MATLAB and type the following in the command prompt

Creates a row vector


• x=[1 2 3 4 5 6 7]
x=[1,2,3,4,5,6,7]

• y=[1;2;3;4;5] Creates a column vector

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


Entry of a matrix
B=[20,12,16,44;54, 4, 62, 28]

• length(x), length(y)
• size(A), size(B)
• B’, transpose(B)

• x1=ones(1,10) Creates a 1 x 10 row vector with all components as ones

• y0=zeros(5,1) Creates a 5 x 1 column vector with all components as ones

• M = zeros(3,4) Creates a 3 x 4 matrix with all components as zero

• eye(4)
Creation of identity matrix
eye(5,8)

• z1=1:10 Creation of a row vector from 1 to 10 with a default increment 1

• z2=5:3:26 a:c:b
z3=26:-3:5 Creation of a row vector from a to b with an increment of c

• L=[1,2,3;4,5,6;7,8,9;8,3,4]
u=L(2,:)
extracts the specific rows, columns, submatrices
v=L(:,3)
w=L(1:2,2:3)
• E=[2,9,12;9,6,-2;2,8,10]
a=E(2,3)
Extracts a specific element from matrix
b=E(1,2)

• E, p=[ 9 8 7], F=[E;p] appends E with a new row vector p


• F, q=[1 2 3 4], G=[F q’] appends F with a new column vector q

• M=[1,2;3,4]; M(:,2)= M(:,2)+1 Replaces the second column [2,4]T to [3,5]T

• x=[9 3 1 5 7] Sorts the vector in ascending or descending order


sort(x,’ascend’), sort(x,’descend’)

• sum(x) Finds the sum, maximum value, minimum value, mean,


max(x), min(x) variance and standard deviation of elements in x
mean(x), var(x), std(x)

• dot(p,q)
dot product and cross product of vectors
• cross(p,q)

• p=[30 20 50]; q=[-20 40 70]; A=[1,2,3;2,3,4;4,5,6]; B=[4,9,4;1,9,16;25,9,4];


p+q, A+B, p-q, A-B Addition and subtraction of Vectors/Matrices

• 2*q, 3*A, B/4 Scalar multiplication to a vector/matrix

• p+2, A+3 Adds two to every element of the vector/matrix

• exp(p), log(p), sqrt(B), sin(A), etc component wise evaluation

• A*B, p*q’, p’*q, A2 Matrix multiplication

• p.*q, A.*B component wise multiplication of vectors/matrices of equal size

Eg: [1 2 3].*[2 3 4]=[2 6 12]

• M=[1,2;3,4]; N=M.^2 Each element of the matrix is squared

• L=[1 2 3;4 5 6;7 8 10];


D=det(L)
Finds the determinant, inverse, trace of the matrix
I=inv(L)
T=trace(L)

DE=diag(L) Finds the diagonal elements and write it as a vector

• V=[2,3,4]; diag(V) Forms a diagonal matrix with elements from vector V


• P=[1,2,3,6;2,3,4,9;3,4,5,12]; Gives row reduced echelon form of the matrix M
rref(P)

Practise Questions (Vectors and Matrices):


1. Evaluate the following for 𝑥̅ = (−9 8 7) , 𝑦̅ = (1,2, −3), 𝑧̅ = (11,0,2) using MATLAB/Octave
(a) 𝑥̅ · 𝑦̅ (b) 𝑥̅ × 𝑦̅ · 𝑧̅ (c) 𝑥̅ · 𝑦̅ × 𝑧̅ (d) (𝑥̅ × 𝑦̅ )×( 𝑧̅×𝑥̅ ) (e) (2𝑥̅ × 5𝑦̅)+ 9𝑧̅
2. The marks of all students in a class for a mathematics exam is given below:
21,99,45,97,15,89,100,78,68,37,44,56,77,88,99,22,19,3,50,44,78,98,86,65,91,51
Answer the questions after entering these marks as a vector in MATLAB/Octave command
window.
(a) How many students are there in the class?
(b) What is the class average in mathematics?
(c) What is the maximum mark? minimum mark?
(d) Write all the marks in (i)ascending order and (ii) descending order.
99 12 3 91 22 35
1 2 3
3. If P=[ 4 43 6 ], Q=[14 42 16] and R= [ ]
4 9 8
77 65 49 72 43 51
(i) Find (a)3P+Q-PQ (b) QRT (c) RQ-R (d) P2Q (e) (P+Q)2 (f) |P| (g) P-1
(ii) Find the vector consisting of diagonal elements of P+Q.
(iii) Find the trace of (i)P+Q and (ii)PQ.
(iv) Create an identity matrix of order 15.
(v) Obtain the third row of P+Q and call it as vector u.
(vi) Obtain a 4×3 matrix by appending P with u.
(vii) Obtain the second column of P+Q
9 1 3
4. If A=[4 4 6], B = [24 56 78] T in the system of equations AX=B.
0 5 4
(i) Write the augmented matrix AB, (ii) Find X=A-1B

10 3 13 931 232 345


5. If P=[44 21 62], Q=[154 462 186], verify (i) (PQ)T=QT PT (ii) PI=IP=P.
7 35 49 722 463 501
6. Create a row vector of all prime numbers between 4 and 40.

7. Create a column vector of all numbers corresponding to the alphabets in your name.
8. Create a 1 x 5 vector A with all elements equal to 0 (without directly entering the rows).
9. Create a 4 x 5 matrix of all zero elements.
10 3 13
10. Create the following Matrix P=[44 21 62]
7 35 49
a. Find the transpose of P;
b. Display the element P13 of the matrix P.
c. Display the second row of the P.
d. Display the third column of P
e. Find the determinant of P
f. Find the inverse of P
g. Multiply P-1P and PP-1
h. Find PPT and PTP
i. Create a matrix which has elements as square of each element of P.
j. Find P3.
k. Create a matrix which has 2 added to each element of P.
l. Find the trace of the following matrices: P-1P, PTP, 3P, -P

11. Use MATLAB commands to create the following matrices (do not enter the matrices directly):

12. Create a diagonal matrix with the diagonal elements as elements of the vector [2, -6, 7, 3, 2, 7].

You might also like