You are on page 1of 3

17BEC0026

Debanik Majumder

DIGITAL ASSIGNMENT - 1

1) Describe the usage of MATLAB for mathematical purpose.


Ans:-
1) Matlab allows matrix manipulations.
2) Matlab makes vectorized operation of adding two arrays together easy because adding two arrays
in matlab needs only one command, instead of a for or while loop.
3) In matlab we can plot our data very easily, and then change colours , sizes and scales etc.
4) In matlab we can perform operations from the command line, as a sophiticated calculator.
5) It is used to perform the basic mathematical operations which ranges from addition to
exponrential form.

2) Explain about M-file in MATLAB.

Ans:-
An M-file or script file, is a simple text file where you can place MATLAB commands.
When the file is run,MATLAB reads the commands and executes them exactly as it would if you
have typed each command sequentially at the MATLAB prompt. All M-file names must end with
the extension '.m'.

3)Find the complete solution to the sequence of equations(Use Matrices


to find the solution) x+3y+3z=1,2x+6y+9z=5,-x-3y+3z=5.
Ans:-

Editor window:-
clc
clearvars
syms x y z
eqn1=x+3*y+3*z==1;
eqn2=2*x+6*y+9*z==5;
eqn3=-x-3*y+3*z==5;
[A,B]=equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
x=linsolve(A,B)

Command window:-
A=

[ 1, 3, 3]
[ 2, 6, 9]
[ -1, -3, 3]
B=

1
5
5

x=

-2
0
1

4) Enterthe matrix M by M=[1 3 – 1 6;2 4 0 – 1;0 – 2 3 – 1; - 1 2 – 5 1]


and also the matrix N=[- 1 – 3 3;2 – 1 6;1 4 – 1;2 – 1 2].Multiply M and
N using M*N. Can the order of multiplication be switched? Why or why
not? Try it to see how Matlab reacts.
Ans:-

Editor window:-
M=[1 3 -1 6;2 4 0 -1;0 -2 3 -1;-1 2 -5 1]
N=[-1 -3 3;2 -1 6;1 4 -1;2 -1 2]
a=M*N

e=eig(M)

Command Window:-

M=

1 3 -1 6
2 4 0 -1
0 -2 3 -1
-1 2 -5 1

N=

-1 -3 3
2 -1 6
1 4 -1
2 -1 2

a=

16 -16 34
4 -9 28
-3 15 -17
2 -20 16

No, the order of multiplication cannot be switched because matlab shows error.

Matlab reacts as follows:-

Error using *
Inner matrix dimensions must
agree.

Error in da10026 (line 3)


a=N*M

5) Discuss the eigen values of M and N.


Ans:-

Eigen value of M-
e=

6.4217 + 0.0000i
0.9472 + 2.2913i
0.9472 - 2.2913i
0.6840 + 0.0000i

Eigen value of N shows error.


Matlab reacts as follows:-

Error using eig


For standard eigenproblem
EIG(A), A must be square.

Error in da10026 (line 5)


e=eig(N)

You might also like