0% found this document useful (0 votes)
180 views103 pages

Magesh 21BMC026 Matlab Task 8 Completed

The document provides instructions on matrix operations in MATLAB, including addition, subtraction, multiplication, transpose, and inverse. Specifically: 1) It defines matrix addition and subtraction as the element-wise addition and subtraction of corresponding elements in the matrices. 2) Matrix multiplication is defined as the usual row-column multiplication, where the number of columns of the first matrix must equal the number of rows of the second matrix. 3) The transpose of a matrix is obtained by interchanging the rows and columns. 4) The inverse of a square matrix A is obtained by calculating A^-1 such that AA^-1 = I, the identity matrix. Examples are provided to demonstrate each operation.

Uploaded by

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

Magesh 21BMC026 Matlab Task 8 Completed

The document provides instructions on matrix operations in MATLAB, including addition, subtraction, multiplication, transpose, and inverse. Specifically: 1) It defines matrix addition and subtraction as the element-wise addition and subtraction of corresponding elements in the matrices. 2) Matrix multiplication is defined as the usual row-column multiplication, where the number of columns of the first matrix must equal the number of rows of the second matrix. 3) The transpose of a matrix is obtained by interchanging the rows and columns. 4) The inverse of a square matrix A is obtained by calculating A^-1 such that AA^-1 = I, the identity matrix. Examples are provided to demonstrate each operation.

Uploaded by

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

MATLAB LABORATORY WORKBOOK

Subject Code : U18MAI1202L-Linear Algebra andCalculus


Regulations : R18
Branches : I B.E/B.Tech
Certificate

This is to certify that it is a bonafide record of practical work


done by Kum. Mageshwaran.K_ bearing the Roll No. 21BMC026 of
B.E/B.TECH_ class Mechatronics branch in the Matlab Laboratory during the
academic year 2021-2022 under our supervision.

Faculty in charge Internal Examiner


TABLE OF CONTENTS

S.No LIST OF EXPERIMENTS Page No

1. Introduction to MATLAB

Matrix Operations - Addition, Multiplication, Transpose,


2.
Inverse
Rank of a matrix and solution of a system of linear
3.
equations.
Characteristic equation of a matrix and Cayley-Hamilton
4.
theorem.

5. Eigenvalues and Eigenvectors of higher order matrices

6. Curve tracing

7. Differentiation & Integration

Solving first and second order ordinary differential


8.
equations.
Determining maxima and minima of a function of one
9.
variable.
Determining maxima and minima of a function of two
10.
variables.

MATLAB - MARKS BREAK UP STATEMENT


S. Progra Execu
Viva Total Staff
No Date Name of the experiment m tion
(10) (30) sign
. (10) (10)

1 Introduction to MATLAB

Matrix Operations - Addition,


2
Multiplication, Transpose,
Inverse

3 Rank of a matrix and solution of


a system of linear equations.

Characteristic equation of a
4
matrix and Cayley-Hamilton
theorem.

5 Eigenvalues and Eigenvectors of


higher order matrices

6 Curve tracing

7 Differentiation and Integration

8 Solving first and second order


ordinary differential equations.

Determining maxima and


9
minima of a function of one
variable.
Determining maxima and
10
minima of a function of two
variables.
WORKSHEET-1

INTRODUCTION TO MATLAB

1.1 OBJECTIVES

a. To know the history and features of MATLAB


b. To know the local environment of MATLAB

1.2 Introduction
MATLAB is a high-level language and interactive environment for numerical
computation, visualization, and programming. Using MATLAB, you can analyze
data, develop algorithms, and create models and applications. The language,
tools, and built-in math functions enable you to explore multiple approaches and
reach a solution faster than with spread sheets or traditional programming
languages, such as C/C++ or Java. You can use MATLAB for a range of
applications, including signal processing and communications, image and video
processing, control systems, test and measurement, computational finance, and
computational biology. More than a million engineers and scientists in industry
and academia use MATLAB, the language of technical computing.

A matrix is a two-dimensional array of numbers.


In MATLAB, you create a matrix by entering elements in each row as comma or space
delimited numbers and using semicolons to mark the end of each row.
For example, let us create a 4-by-5 matrix a −

a =[12345;23456;34567;45678]

MATLAB will execute the above statement and return the following result −
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8

Referencing the Elements of a Matrix


To reference an element in the mth row and nth column, of a matrix mx, we write −
mx(m, n);
For example, to refer to the element in the 2 nd row and 5th column, of the matrix a, as
created in the last section, we type −

a =[12345;23456;34567;45678];

a(2,5)

MATLAB will execute the above statement and return the following result −
ans= 6

To reference all the elements in the mth column we type A(:,m).


Let us create a column vector v, from the elements of the 4 th row of the matrix a −

a =[12345;23456;34567;45678];

v = a(:,4)

MATLAB will execute the above statement and return the following result −
v =
4
5
6
7

You can also select the elements in the mth through nth columns, for this we write −

a(:,m:n)

Let us create a smaller matrix taking the elements from the second and third columns −

a =[12345;23456;34567;45678];

a(:,2:3)

MATLAB will execute the above statement and return the following result −
ans =
2 3
3 4
4 5
5 6

In the same way, you can create a sub-matrix taking a sub-part of a matrix.

a =[12345;23456;34567;45678];

a(:,2:3)

MATLAB will execute the above statement and return the following result −
ans =
2 3
3 4
4 5
5 6

In the same way, you can create a sub-matrix taking a sub-part of a matrix.
For example, let us create a sub-matrix sa taking the inner subpart of a −
3 4 5
4 5 6

a =[12345;23456;34567;45678];

sa=a(2:3,2:4)

MATLAB will execute the above statement and return the following result −
sa =
3 4 5
4 5 6

Deleting a Row or a Column in a Matrix


You can delete an entire row or column of a matrix by assigning an empty set of square
braces [] to that row or column. Basically, [] denotes an empty array.
For example, let us delete the fourth row of a −

a =[12345;23456;34567;45678];

a(4,:)=[]

MATLAB will execute the above statement and return the following result −
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7

Next, let us delete the fifth column of a −

a =[12345;23456;34567;45678];

a(:,5)=[]
MATLAB will execute the above statement and return the following result −
a =
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

Example

In this example, let us create a 3-by-3 matrix m, then we will copy the second and third
rows of this matrix twice to create a 4-by-3 matrix.
Create a script file with the following code −

a =[123;456;789];

new_mat=a([2,3,2,3],:)

When you run the file, it displays the following result −


new_mat =
4 5 6
7 8 9
4 5 6
7 8 9
Task 1

1. Try these commands:


>> 3*5*6
90

>> z1 = 34; z2 = 17; z3 = -8;

>> z1/z2

2
>> z1-z3

42
>> z2+z3-z1

-25

2. Determine the value of the expression a(b + c(c + d))a, where a = 2, b = 3, c =


−4,d = −3.

>> a = 2; b = 3; c = -4; d = -3;


a*(b+c*(c+d))*a
>> a*(b+c*(c+d))*a
124

3. Evaluate the MATLAB expression

>>1+2/3*4-5
-1.3333

>>1/2/3/4
0.0417

>>1/2+3/4*5
4.2500

>>5-2*3*(2+7)
-49

>>(1+3)*(2-3)/3*4
-5.3333
>>(2-3*(4-3))*4/5
-0.8000
4. Calculate the expressions:
(1) sin 600 in radians
Sin(60)
-0.3048

(2) sin 600 in degree


sind(60)
0.8660

(3) elog4
exp(log(4))

4
(4) cos 450 - sin 450
cosd(45)-sind(45)

(5) log e2
log(exp(2))

2
5. Create two vectors running from one to six and from six to one and then
demonstrate the use of the dot arithmetical operations:s+t, s-t, st, s/t, s 2, 1/s, s/2,
s+1

s=1: t=6:-1:1
(i) s+t
Output:
ans =

7 7 7 7 7 7
(ii) s-t
Output:
ans =

-5 -3 -1 1 3 5

(iii) s*t
Output:
ans =

6 10 12 12 10 6

(iv) s./t
Output:

ans =

0.1667 0.4000 0.7500 1.3333 2.5000 6.0000

(v) s.^2
Output:
ans =

1 4 9 16 25 36
(vi) 1./s
Output:
ans =

1.0000 0.5000 0.3333 0.2500 0.2000 0.1667

(vii) s./2
Output:
ans =

0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

(viii) s+1
Output:
ans =

2 3 4 5 6 7

6. Construct the polynomial y = (x + 2) 2(x3 + 1) for values of x from minus one to


one in steps of 0.1.

PROGRAM:
x=-1:0.1:1
y=((x+2).^2).*(x.^3+1)
poly(y)
OUTPUT:

ans =

1.0e+13 *

Columns 1 through 9

0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0001 -0.0006 0.0043


Columns 10 through 18

-0.0238 0.1042 -0.3618 0.9925 -2.1333 3.5459 -4.4696 4.1497 -2.7152

Columns 19 through 22

1.1663 -0.2891 0.0304 0

7. Find the roots of the polynomial y = x3 − 3x2 + 2x


PROGRAM:
x=[1 -3 2 0]
roots(x)

OUTPUT:

ans =

0
2
1

WORKSHEET-2
MATRIX OPERATIONS -
ADDITION, MULTIPLICATION, TRANSPOSE, INVERSE

2.1 OBJECTIVES:

 To evaluate the addition, subtraction and multiplication of two Matrices.

 To evaluate the transpose and inverse of a Matrix.

2.2 MATRIX ADDITION

( ) ( )
1 2 4 0 3 6
A= 0 5 6 B= 7 1 −1
7 8 4 5 7 −9
Example 1:Find the addition of the matrices and

A=[1 2 4 ; 0 5 6; 7 8 4];
B=[0 3 6; 7 1 -1; 5 7 9];
disp('The matrix A= ');A
disp('The matrix B= ');B
% to find sum of A and B,C=A+B;
disp('The sum of A and B is ');
C=A+B
Output:
The matrix A=

A=

1 2 4
0 5 6
7 8 4

The matrix B=
B=

0 3 6
7 1 -1
5 7 9
The sum of A and B is

C=

1 5 10
7 6 5
12 15 13

MATRIX MULTIPLICATION:

( ) ( )
1 2 4 0 3 6
A= 0 5 6 B= 7 1 −1
Example 2:Find the multiplication of the matrices 7 8 4 and 5 7 −9

A=[1 2 4 ; 0 5 6; 7 8 4];
B=[0 3 6; 7 1 -1; 5 7 9];
disp('The matrix A= ');A
disp('The matrix B= ');B
disp('The multiplication of A and B is ');
C=A*B

Output:

The matrix A=

A=

1 2 4
0 5 6
7 8 4

The matrix B=

B=

0 3 6
7 1 -1
5 7 9

The multiplication of A and B is

C=
34 33 40
65 47 49
76 57 70

MATRIX TRANSPOSE AND INVERSE.

( )
1 2 4
A= 0 5 6
Example 3: Find the transpose and inverse of the matrix 7 8 4

A=[1 2 4 ; 0 5 6; 7 8 4];
disp('The matrix A= ');A
% to find transpose of A;
disp('The transpose of A is ');A'
% to find inverse of A;
disp('The inverse of A is ');
inv(A)
Output:
The matrix A=
A=
1 2 4
0 5 6
7 8 4

The transpose of A is
ans =

1 0 7
2 5 8
4 6 4

The inverse of A is
ans =

0.3333 -0.2857 0.0952


-0.5000 0.2857 0.0714
0.4167 -0.0714 -0.0595
Task 2

( )
5 2 12
A= 0 19 16
17 8 6
Find the addition and subtraction of the matrices and

1.

( )
8 13 8
B= 15 10 −1
5 9 −9

PROGRAM:
A=[5 2 12;0 19 16;17 8 6];
B=[8 13 8;15 10 -1;5 9 -9];
disp('The matrix of A is');A
disp('The matrix of B is');B
disp('The sum of A and B is');C=A+B
disp('The difference of A and B is');D=A-B

OUTPUT:

The matrix of A is

A=

5 2 12

0 19 16

17 8 6
The matrix of B is

B=

8 13 8

15 10 -1

5 9 -9

The sum of A and B is

C=

13 15 20

15 29 15

22 17 -3

The difference of A and B is


D=

-3 -11 4

-15 9 17

12 -1 15

( ) ( )
11 2 14 10 8 6
A= 10 5 60 B= 7 1 −11
17 8 4 9 7 −9
Find the multiplication of the matrices and

2.

PROGRAM:
A=[11 2 14;10 5 60;17 8 4];
B=[10 8 6;7 1 -11;9 7 -9];
disp('The matrix of A is');A
disp('The matrix of B is');B
disp('The multiplication of A and B is');C=A*B
OUTPUT:
The matrix of A is

A=

11 2 14
10 5 60
17 8 4

The matrix of B is

B=

10 8 6
7 1 -11
9 7 -9

The multiplication of A and B is

C=
250 188 -82
675 505 -535
262 172 -22

( )
1 22 4
A= 18 5 16
Find the transpose and inverse of the matrix 7 28 4

3.

PROGRAM:
A=[1 22 4;18 5 16;7 28 4];

disp('The matrix of A is');A


disp('The transpose of A');A'
disp('The inverse of A is');inv(A)
OUTPUT:
The matrix of A is

A=

1 22 4
18 5 16
7 28 4

The transpose of A

ans =

1 18 7
22 5 28
4 16 4

The inverse of A is

ans =

-0.1838 0.0103 0.1426


0.0172 -0.0103 0.0241
0.2015 0.0541 -0.1680
( ) ( )
6 2 4 12 21 14
A= 8 5 6 B= 11 15 36
4. Find the matrix multiplication of the two matrices 7 8 4 17 68 24

, .
PROGRAM:
A=[6 2 4;8 5 6;7 8 4];
B=[12 21 14;11 15 36;17 68 24];
disp('The matrix of A is');A
disp('The matrix of B is');B
disp('The multiplication of A and B is');C=A*B
OUTPUT:
The matrix of A is

A=

6 2 4
8 5 6
7 8 4

The matrix of B is

B=

12 21 14
11 15 36
17 68 24

The multiplication of A and B is

C=

162 428 252


253 651 436
240 539 482

( )
91 24 42
A= 18 52 48
72 45 64

5. Find the transpose and inverse of the matrix


A=[91 24 42;18 52 48;72 45 64];
PROGRAM:
disp('The matrix of A is');A
disp('The transpose of A');A'
disp('The inverse of A is');inv(A)

OUTPUT:

The matrix of A is

A=

91 24 42

18 52 48

72 45 64

The transpose of A

ans =

91 18 72

24 52 45

42 48 64

The inverse of A is
ans =

0.0305 0.0092 -0.0269

0.0601 0.0730 -0.0942

-0.0765 -0.0617 0.1121

WORKSHEET-3
RANK OF A MATRIX AND SOLUTION OF A SYSTEM OF LINEAR EQUATIONS

3.1 OBJECTIVES:

 To find the rank of a matrix

 To solve the system of linear equations

 To find the echelon form of the matrix.


3.2 PROGRAM

RANK OF THE MATRIX

( )
1 2 3 2
A= 2 3 5 1
Example 1: Find the rank of the matrices 1 3 4 5
A=[1 2 3 2;2 3 5 1;1 3 4 5]
disp('The matrix A= ');A
% To find rank of A
disp('The rank of A is ');
C=rank(A)

Output:
The matrix A=

A=

1 2 3 2
2 3 5 1
1 3 4 5

The rank of A is

C=

ECHELON FORM OF THE MATRIX

( )
1 2 3 2
A= 2 3 5 1
Example 2.Find the echelon form of the matrix 1 3 4 5
A=[1 2 3 2;2 3 5 1;1 3 4 5]
disp('The matrix A= ');A
% to find rank of A ;
disp('The echelon form of A is ');
D=rref(A)
Output:
The matrix A=

A=

1 2 3 2
2 3 5 1
1 3 4 5
The echelon form of A is

D =

1 0 1 -4
0 1 1 3
0 0 0 0

SOLUTION OF SYSTEM OF LINEAR EQUATIONS.

Example 3: Solving system of linear equations 2x+y+z=2; -x+y-z=3; x+2y+3z=-10.

syms x y z
eqn1 = 2*x + y + z == 2;
eqn2 = -x + y - z == 3;
eqn3 = x + 2*y + 3*z == -10;
[A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z])
X = linsolve(A,B)

Output:

A=
[ 2, 1, 1]
[ -1, 1, -1]
[ 1, 2, 3]
B=
2
3
-10
X=
3
1
-5

Task 3

( )
1 1 1 3
A= 1 1 −1 1
1. Find the rank of the matrices 3 3 −5 1

PROGRAM:
A=[1 1 1 3;1 1 -1 1;3 3 -5 1]
disp('The rank of A is :'); rank=rank(A)
OUTPUT:

A=

1 1 1 3

1 1 -1 1

3 3 -5 1

The rank of A is :

rank =

( )
−2 1 1 1
A= 1 −2 1 1
2. Find the echelon form of the matrix 1 1 −2 1
PROGRAM:
A=[-2 1 1 1;1 -2 1 1;1 1 -2 1]
disp('The echelon form of A is :'); B=rref(A)
OUTPUT:
A=

-2 1 1 1
1 -2 1 1
1 1 -2 1

The echelon form of A is :

B=

1 0 -1 0
0 1 -1 0
0 0 0 1

3. Solving system of linear equations


x+2 y−z=4
x+3 y−2 z=5
2x− y+3 z=3

PROGRAM:
syms x y z
eqn1 = x+2*y-z==4;
eqn2 = x+3*y-2*z==5;
eqn3 = 2*x-y+3*z==3;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)
OUTPUT:
A=

[ 1, 2, -1]
[ 1, 3, -2]
[ 2, -1, 3]

B=

4
5
3

Warning: The system is rank-deficient. Solution is not unique.


> In symengine
In sym/privBinaryOp (line 908)
In sym/linsolve (line 63)
In Untitled2 (line 6)

X=

2
1
0
[ ]
2 1 2 1
6 −6 6 12
A=
4 3 3 −3
4. Find the row echelon form of the matrix
2 2 −1 1

PROGRAM:
A=[2 1 2 1;6 -6 6 12;4 3 3 -3;2 2 -1 1]
disp('The echelon form of A is');B=rref(A)
OUTPUT:
A=

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

The echelon form of A is

B=

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

( )
4 −5 1 2
A= 3 1 −2 9
5. Find the rank of the matrix 1 4 1 5

A=[4 -5 1 2;3 1 -2 9;1 4 1 5]


PROGRAM:
rank(A)
OUTPUT:
A=

4 -5 1 2
3 1 -2 9
1 4 1 5

ans =

3
6. Solving system of linear equations
x+2 y+z=3
2 x+3 y+2 z=5
3 x−5 y+5 z=2
3 x+9 y−z=4
PROGRAM:
syms x y z
eqn1 = x+2*y+z==3;
eqn2 = 2*x+3*y+2*z==5;
eqn3 = 3*x-5*y+5*z==2;
eqn4 = 3*x+9*y-z==4;
[A,B]= equationsToMatrix([eqn1,eqn2,eqn3,eqn4],[x,y,z])
X = linsolve(A,B)
OUTPUT:
A=

[ 1, 2, 1]
[ 2, 3, 2]
[ 3, -5, 5]
[ 3, 9, -1]

B=

3
5
2
4

X=

-1
1
2

WORKSHEET-4
CHARACTERISTIC EQUATION OF A MATRIX AND CAYLEY-HAMILTON THEOREM

4.1 OBJECTIVES

 To verify Cayley Hamilton Theorem and find the inverse of the matrix

4.2 Example 1:Verify Cayley Hamilton Theorem for the matrix


A= (12 34 )
Program:
A=[1 3;2 4]
disp('The matrix A= ');A
% to find the polynomial of A ;
X=poly(A)
disp('The polynomial of A is ');
round(X)
y=polyvalm(X,A)
disp(' Cayley Hamilton theorem ');
round(y)
disp('The identity matrix is ');
i=eye(2,2)
disp('The inverse of A is ');
InvA=(A-5*i)/2
s=inv(A)
Output:
The matrix A=
A=
1 3
2 4
X = 1.0000 -5.0000 -2.0000
The polynomial of A is
ans = 1 -5 -2
Cayley Hamilton theorem
ans =
0 0
0 0
The identity matrix is
i=
1 0
0 1
The inverse of A is
InvA =
-2.0000 1.5000
1.0000 -0.5000
s=
-2.0000 1.5000
1.0000 -0.5000

( )
1 −1 4
A= 3 2 1
Example 2:Verify Cayley Hamilton Theorem for the matrix 2 1 −1
Program:
A=[1 -1 4;3 2 1;2 1 -1]
disp('The matrix A= ');A
% to find the polynomial of A ;
X=poly(A)
disp('The polynomial of A is ');
round(X)
y=polyvalm(X,A)
disp(' Cayley Hamilton theorem ');
round(y)
disp('The identity matrix is ');
i=eye(3,3)
disp('The inverse of A is ');
InvA=(-A^2+2*A+7*i)/12
s=inv(A) (Hint:)
Output:

The matrix A=
A=
1 -1 4
3 2 1
2 1 -1
X = 1.0000 -2.0000 -7.0000 12.0000
The polynomial of A is
ans = 1 -2 -7 12 --------- A3 −2 A 2−7 A +12i=0−−−−−¿
Cayley Hamilton theorem
ans =
0 0 0
0 0 0
0 0 0
The identity matrix is
i=
1 0 0
0 1 0
0 0 1
The inverse of A is
InvA =0.2500 -0.2500 0.7500
-0.4167 0.7500 -0.9167
0.0833 0.2500 -0.4167
s = 0.2500 -0.2500 0.7500
-0.4167 0.7500 -0.9167
0.0833 0.2500 -0.4167

Task 4:
1. Verify Cayley Hamilton theorem for the matrix and find the value of

( )
1 0 3
A= 2 1 −1
1 −1 1
PROGRAM:
A=[1 0 3;2 1 -1;1 -1 1]
x=poly(A)
round(x)
y=polyvalm(x,A)
display('Cayley Hamilton Theorem :');round(y)
i=eye(3)
InvA=(-A^2+3*A+i)/9
display('Inverse of A is :');InvA

OUTPUT:
A=

1 0 3
2 1 -1
1 -1 1

x=

1.0000 -3.0000 -1.0000 9.0000

ans =

1 -3 -1 9

y=

1.0e-13 *

0.0178 -0.0933 0.0888


0.0311 -0.0355 0.1421
-0.0311 -0.0311 0.0533

Cayley Hamilton Theorem :

ans =
0 0 0
0 0 0
0 0 0

i=

1 0 0
0 1 0
0 0 1

InvA =

0 0.3333 0.3333
0.3333 0.2222 -0.7778
0.3333 -0.1111 -0.1111

Inverse of A is :

InvA =

0 0.3333 0.3333
0.3333 0.2222 -0.7778
0.3333 -0.1111 -0.1111

2. Verify Cayley Hamilton theorem for the matrix and find .


( )
1 3 7
A= 4 2 3
1 2 1

PRODUCT:
A=[1 3 7;4 2 3;1 2 1]
x=poly(A)
round(x)
y=polyvalm(x,A)
display('Cayley Hamilton Theorem :');round(y)
i=eye(3)

display('Inverse of A is :');InvA=((-A^2+4*A+20*i)/-35)

OUTPUT:
A =

1 3 7
4 2 3
1 2 1

x =

1.0000 -4.0000 -20.0000 -35.0000

ans =

1 -4 -20 -35

y =

1.0e-13 *

-0.7105 -0.5862 -0.7105


-0.4263 -0.7105 -0.9592
-0.2753 -0.2309 -0.4263

Cayley Hamilton Theorem :

ans =

0 0 0
0 0 0
0 0 0
i =

1 0 0
0 1 0
0 0 1

Inverse of A is :

InvA =

-0.1143 0.3143 -0.1429


-0.0286 -0.1714 0.7143
0.1714 0.0286 -0.2857

3. Verify Cayley Hamilton theorem for the matrix and find .

( )
1 2 3
A= 2 −1 4
3 1 −1

PRODUCT:
A=[1 2 3;2 1 -4;3 1 -1]
x=poly(A)
round(x)
y=polyvalm(x,A)
display('Cayley Hamilton Theorem :');round(y)
i=eye(3)

display('Inverse of A is :');InvA=((-A^2+A+10*i)/20)
%s=inv(A)

OUTPUT:

A=
1 2 3

2 1 -4

3 1 -1

x=

1.0000 -1.0000 -10.0000 20.0000

ans =

1 -1 -10 20

y=

1.0e-13 *

-0.1776 -0.1243 0.1243

0.0888 0 -0.0888
-0.0488 -0.0711 -0.0711

Cayley Hamilton Theorem :

ans =

0 0 0

0 0 0

0 0 0

i=

1 0 0

0 1 0

0 0 1

Inverse of A is :

InvA =
-0.1500 -0.2500 0.5500

0.5000 0.5000 -0.5000

0.0500 -0.2500 0.1500

4 . Verify Cayley Hamilton theorem for the matrix and find .

( )
2 1 1
A= 0 1 0
1 1 2

PRODUCT:
A=[2 1 1;0 1 0;1 1 -2]
x=poly(A)
round(x)
y=polyvalm(x,A)
display('Cayley Hamilton Theorem :');round(y)
i=eye(3)

display('Inverse of A is :');InvA=((-A^2+A+5*i)/5)

OUTPUT:

A=

2 1 1

0 1 0

1 1 -2
x=

1.0000 -1.0000 -5.0000 5.0000

ans =

1 -1 -5 5

y=

1.0e-14 *

-0.0888 -0.0888 -0.0888

0 0 0

-0.0888 -0.0888 0.2665

Cayley Hamilton Theorem :

ans =
0 0 0

0 0 0

0 0 0

i=

1 0 0

0 1 0

0 0 1

Inverse of A is :

InvA =

0.4000 -0.6000 0.2000

0 1.0000 0

0.2000 0.2000 -0.4000

5. Verify Cayley Hamilton theorem for the matrix and find .


( )
1 0 −1
A= 3 4 5
0 −6 −7

PRODUCT:
A=[1 0 -1;3 4 5;0 -6 -7]
x=poly(A)
round(x)
y=polyvalm(x,A)
display('Cayley Hamilton Theorem :');round(y)
i=eye(3)

display('Inverse of A is :');InvA=((-A^2-2*A+i)/-20)

OUTPUT:

A=

1 0 -1

3 4 5

0 -6 -7

x=

1.0000 2.0000 -1.0000 -20.0000

ans =
1 2 -1 -20

y=

1.0e-13 *

0.4263 0 -0.1243

0.4263 0.7816 0.6395

0 -0.7105 -0.5684

Cayley Hamilton Theorem :

ans =

0 0 0

0 0 0

0 0 0

i=
1 0 0

0 1 0

0 0 1

Inverse of A is :

InvA =

0.1000 0.3000 0.2000

1.0500 -0.3500 -0.4000

-0.9000 0.3000 0.2000


WORKSHEET-5
EIGENVALUES AND EIGENVECTORS OF HIGHER ORDER MATRICES

5.1 OBJECTIVES

 To find the Eigenvalues and Eigenvectors of the matrix

5.2 Example 1: Find the eigenvalues and eigenvectors of the matrix

( )
1 −1 0
A= −1 2 1
0 1 1
Program:
A=[1 -1 0 ; -1 2 1 ; 0 1 1]
disp(' The Eigenvalues of A are ');
eig(A)
disp(' The Eigenvector of A are ');
[v,d]=eig(A)
round([v,d])

Output:
A=
1 -1 0
-1 2 1
0 1 1
The eigenvalues of A are
ans =
0.0000
1.0000
3.0000
The Eigenvector of A are
v=
0.5774 0.7071 -0.4082
0.5774 -0.0000 0.8165
-0.5774 0.7071 0.4082
d=
0.0000 0 0
0 1.0000 0
0 0 3.0000
ans =
1 1 0 0 0 0
1 0 1 0 1 0
-1 1 0 0 0 3

Example 2: Find the eigenvalues and eigenvectors of the matrix

( )
1 −3 2 −1
−3 9 −6 3
B=
2 −6 4 −2
−1 3 −2 1

Program:
B=[1 -3 2 -1 ; -3 9 -6 3 ; 2 -6 4 -2 ; -1 3 -2 1]
disp(' The Eigenvalues of B are ');
eig(B)
disp(' The Eigenvector of B are ');
[v,d]=eig(B)
round([v,d])

Output:
B=
1 -3 2 -1
-3 9 -6 3
2 -6 4 -2
-1 3 -2 1
The Eigenvalues of B are
ans =
-0.0000
-0.0000
0.0000
15.0000
The Eigenvector of B are
v=
0.0481 0.9649 0.0069 -0.2582
0.1516 0.1956 0.5820 0.7746
-0.2712 -0.1304 0.8017 -0.5164
-0.9493 0.1173 -0.1357 0.2582
d=
-0.0000 0 0 0
0 -0.0000 0 0
0 0 0.0000 0
0 0 0 15.0000
ans =
0 1 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 0 1 -1 0 0 0 0
-1 0 0 0 0 0 0 15
Task: 5

Find the eigenvalues and eigenvectors of A=

1.

PRODUCT:

A=[11 -4 -7;7 -2 -5;10 -4 -6]


disp('The eigen values of A are :');eig(A)
disp('The eigen vectors of A are :');
[v,d]=eig(A)
round([v,d])

OUTPUT:

A=
11 -4 -7

7 -2 -5

10 -4 -6

The eigen values of A are :

ans =

2.0000
-0.0000

1.0000

The eigen vectors of A are :

v=

-0.6667 0.5774 0.4082

-0.3333 0.5774 -0.4082

-0.6667 0.5774 0.8165


d=

2.0000 0 0

0 -0.0000 0

0 0 1.0000

ans =

-1 1 0 2 0 0
0 1 0 0 0 0

-1 1 1 0 0 1

( )
2 0 −1
A= 0 2 0
Find the eigenvalues of given that −1 0 2

2.

PROGRAM:

A=[2 0 -1;0 2 0;-1 0 2]


B=inv(A)
disp('The eigen values of B are :');eig(B)
disp('The eigen vectors of B are :');
[v,d]=eig(B)
round([v,d])

OUTPUT:

A=

2 0 -1

0 2 0

-1 0 2

B=
0.6667 0 0.3333

0 0.5000 0

0.3333 0 0.6667

The eigen values of B are :

ans =

0.3333

0.5000
1.0000

The eigen vectors of B are :

v=

0.7071 0.0000 0.7071

0.0000 -1.0000 -0.0000

-0.7071 -0.0000 0.7071


d=

0.3333 0 0

0 0.5000 0

0 0 1.0000

ans =

1 0 1 0 0 0
0 -1 0 0 0 0

-1 0 1 0 0 1

Compute the eigenvalues and eigenvectors of the matrix

3.

PROGRAM:

A=[6 -2 2;-2 3 -1;2 -1 3]

disp('The eigen values of A are :');eig(A)


disp('The eigen vectors of A are :');
[v,d]=eig(A)
round([v,d])
OUTPUT:

A=

6 -2 2

-2 3 -1

2 -1 3

The eigen values of A are :

ans =
2.0000

2.0000

8.0000

The eigen vectors of A are :

v=

-0.0487 0.5753 0.8165


0.6559 0.6349 -0.4082

0.7532 -0.5157 0.4082

d=

2.0000 0 0

0 2.0000 0

0 0 8.0000
ans =

0 1 1 2 0 0

1 1 0 0 2 0

1 -1 0 0 0 8

( )
4 −20 −10
A= −2 10 4
Find the eigenvalues and eigenvectors of 6 −30 −13

4.
PROGRAM:
A=[4 -20 -10;-2 10 4;6 -30 -13]

disp('The eigen values of A are :');eig(A)


disp('The eigen vectors of A are :');
[v,d]=eig(A)
round([v,d])

OUTPUT:

A=

4 -20 -10

-2 10 4

6 -30 -13

The eigen values of A are :


ans =

-1.0000

0.0000

2.0000

The eigen vectors of A are :

v=
-0.8944 0.9806 0.0000

0.0000 0.1961 0.4472

-0.4472 -0.0000 -0.8944

d=

-1.0000 0 0

0 0.0000 0

0 0 2.0000
ans =

-1 1 0 -1 0 0

0 0 0 0 0 0

0 0 -1 0 0 2

( )
−2 2 −3
A= 2 1 −6
Find the eigenvalues and eigenvectors of −1 −2 0

5.
PROGRAM:

A=[-2 2 3;2 1 -6;-1 -2 0]

disp('The eigen values of A are :');eig(A)


disp('The eigen vectors of A are :');
[v,d]=eig(A)
round([v,d])

OUTPUT:

A=

-2 2 3

2 1 -6

-1 -2 0
The eigen values of A are :

ans =

-2.1623

4.1623

-3.0000

The eigen vectors of A are :


v=

-0.9400 0.0724 -0.8944

0.3051 0.8921 0.4472

-0.1525 -0.4460 -0.0000

d=

-2.1623 0 0
0 4.1623 0

0 0 -3.0000

ans =

-1 0 -1 -2 0 0

0 1 0 0 4 0

0 0 0 0 0 -3
WORKSHEET-6

CURVE TRACING

6.1 OBJECTIVES
 To plot a two dimensional plot.
 To plot a three dimensional plot.

6.2Example 1:Plot the simple function y = x for the range of values for x from 0 to
100, with an increment of 5.

x = [0:5:100];
y = x;
plot(x, y)
100

90

80

70

60

50

40

30

20

10

0
0 10 20 30 40 50 60 70 80 90 100

Example 2: Plot the function y = x2

x = [-100:20:100];
y = x.^2;
plot(x, y)

10000

9000

8000

7000

6000

5000

4000

3000

2000

1000

0
-100 -80 -60 -40 -20 0 20 40 60 80 100

Example 3: Plot the function y=sin x

x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x)
Graph'), grid on, axis equal
Sin(x) Graph

1
Sin(x)

-1

-2

-3

0 1 2 3 4 5 6 7 8 9 10
x

Example 4: Plot multiple functions on the same graph for the curve y=sin x and
g = cos x

x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('sin(x)', 'cos(x)')

1
Sin(x)
0.8 Cos(x)

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7 8 9 10

Example 5. Draw the graph of two polynomials f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and
g(x) = 5x3 + 9x + 2.

x = [-10 : 0.01: 10];


y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')
4
x 10
3.5

2.5

1.5

0.5

-0.5

-1
-10 -8 -6 -4 -2 0 2 4 6 8 10

2 2
x y
+ =1
Example 6. Plot the curve 4 9
ezplot('x^2/4+y^2/9=1');
axis equal;

3-D Plot
2 2
−( x + y )
Example 7. Create a 3D surface map for the function g=xe .

[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)

0.5

-0.5
2
1 2
0 1
0
-1 -1
-2 -2

Task: 6

1. Plot the sine-wave curve y=sinx such that x varies from 0 to 2 with h=/100.

PROGRAM:
x=[0:pi/100:2*pi];
y=sin(x);
plot(x,y)
xlabel('x')
ylabel('sin(x)')
title('sin(x) Graph')

OUTPUT:
8 7 6 5 4 3
2. For f (x )=8 x −7 x +12 x −5 x +8 x +13 x −12 x+ 9 , compute f(2),roots of f(x) and
plot for x= 0 to 20 in step of 0.1.

PROGRAM:
x=[0:0.1:20];
y=(8*x.^8)-(7*x.^7)+(12*x.^6)-(5*x.^5)+(8*x.^4)+(13*x.^3)-12*x+9;
f=polyvalm(x,2)
a=[8 -7 12 -5 8 13 0 12 9];
roots(a)
plot (x,y)

OUTPUT:
f=

3.2139e+59

ans =

1.0326 + 0.7489i
1.0326 - 0.7489i
-0.2873 + 1.1658i
-0.2873 - 1.1658i
0.3608 + 0.9535i
0.3608 - 0.9535i
-0.6687 + 0.1194i
-0.6687 - 0.1194i

3. Plot the curve y = e-x sin(2x + 3)


PROGRAM:
x=[0:0.1:20];
y=exp(-x).*sin(2*x+3);
plot(x,y,' r')

OUTPUT:

2
+( x + y 2)
4.Create a 3D surface map for the function g=xe .
PROGRAM:
[x,y] = meshgrid(-2:.2:2);
g=x.*exp(x.^2+y.^2);
surf(x,y,g)

OUTPUT:
5. Plot the curve y = x3
PROGRAM:

x=[-10:1:10];
y=x.^3;
plot(x,y,'*')

OUTPUT:
WORKSHEET-7

DIFFRENTIATION AND INTEGRATION

7.1 OBJECTIVES:
 To do differentiation and Integration

 To differentiate:diff(x)
The ‘diff’ operator will return the difference between the n and n+1 row or
column of data if applied to an array of numbers. When applied to symbolic
variables, ‘diff’ will return the approximate derivative. The derivative, as defined
geometrically, is the tangent of a curve at a given point. When applied to a
function, the derivative returns a new function that is the tangent at every point
in the domain. Mathematically, this derivative is the infinitesimally small change
in the dependent variable from point a to a+h, over the change in h, where h
approaches 0 (similar to rise/run or slope for linear equations). The derivative of
our function f(x) is equal to cos(x).

Example 1: Find the differentiation of sin(x)

>> f=sin(x)
>> d=diff(f)
d=cos(x)
>> subs(d,pi)
ans=-1

 To Integrate:int(x)
The opposite of a derivative is the integral, or the anti-derivative, which provides the
area under a curve. The first fundamental theorem of calculus guarantees that a
continuous function will have an antiderivative, ‘int’ which allows us to both determine
the explicit and numerical solutions to an equation. We can further use ‘int’ to calculate
both the indefinite (int(f)) and definite integrals over the range of a to b (int(f,a,b)). Let’s
evaluate the integral of f(x), both based on the indefinite integral and over the range of 0
to pi.

Example 2: Find the integration of cos(x)

>>f=cos(x)
>>ans=int(f)
ans=sin(x)
>> int(ans,0,pi/2)
ans=1

Example 3:
Just like the ‘diff’ function, we can utilize the ‘int’ function to evaluate an equation with
respect to x (dx), y (dy) or z (dz). This is specified with the 2nd argument (i.e. ‘int(g,x)’).
If a definite integral is to be performed, this can be done using 4 arguments, with limits
a to b specified (i.e. ‘int(g,y,a,b)’).

>> int(g,y)
ans =(x*y^3)/3 - y*sin(z)
>> int(g,y,0,2)
ans =(8*x)/3 - 2*sin(z)

Example 4:
We can even evaluate multiple integrals for functions with more than one variable.
While a single integral can be thought of as the area under the curve, a double integral
can be visualized as the volume underneath a surface.

1 2

∫∫ xy 2 dxdy
Let’s take the following double integral for example: 0 0
>>h = x*y^2;
h =x*y^2;
>>h_intx = int(h,x,0,2)
h_intx =2*y^2
>>h_doubleint int(h_intx,y,0,1)
h_doubleint= 2/3
TASK: 7

f (t )=3 t 2 +2t 2
1) Compute the derivative of the function

PROGRAM:
syms t;
f=3*t^2+2*t^2;
a=diff(f)

OUTPUT:
syms t;
f=3*t^2+2*t^2;
a=diff(f)

3 2
2) Find the differentiation of f (x )=18 x +12 x +5 x

PROGRAM:
syms x;
f=18*x^3+12*x^2+5*x;
ans=diff(f)

OUTPUT:

ans =

54*x^2 + 24*x + 5
2
cos(3 x +2 x+1)
3) Compute the derivative of

PROGRAM:
syms x;
f=cos(3*x^2+2*x+1);
a=diff(f)

OUTPUT:
a=

-sin(3*x^2 + 2*x + 1)*(6*x + 2)

2 3 5

∫∫∫ xyz 3 dxdydz


4) Integrate 0 0 3

PROGRAM:
syms x y z;
h=x*y*z.^3;
a=int(int(int(h,x,3,5),y,0,3),z,0,2)

OUTPUT:
a=

144
2 8

∫∫ a 2 c 5 da dc
5) Find the value of 0 5

PROGRAM:
syms a c
h=(a^2)+(c^5);
a=int(int(h,a,5,8),c,0,2)

OUTPUT:
a=

290

2 3 5

∫∫∫ u3 v 2 w 5 dudvdw
0 0 3

6) Compute the value of

PROGRAM:
syms u v w
h=u^3*v^2*w^5;
a=int(int(int(h,u,3,5),v,0,3),w,0,2)

OUTPUT:
a=

13056
WORKSHEET- 8
SOLVING FIRST AND SECOND ORDER ORDINARY DIFFERENTIAL
EQUATIONS

8.1 OBJECTIVES
 To solve the first order ordinary differential equations
 To solve the second order ordinary differential equations

dy
=5 y
.2Example 1: Solve dx
8

%Solving first order ODE


s = dsolve('Dy = 5*y')
Output:
s=
C2*exp(5*t)

df
=−2 f +cos t
Example 2. Solve dt
%Solving First order ODE
f= dsolve('Df = -2*f + cos(t)','t')
Output:
f=
(2*cos(t))/5 + sin(t)/5 + C4*exp(-2*t)

Example 3. Solve
dx
+
x
dy 1+ y 2
=tan
−1 y
( )
1+ y 2
% LEIBNITZ'S FORM - EX2
x=dsolve('Dx+(1/(1+y^2))*x=atany/(1+y^2)','y')
Output:

x= atany- C10*exp(-atan(y))
2 '
Example 4: Solve ( D −1) y=0; y(0)=−1 ∧ y (0)=2

y=dsolve('D2y - y = 0','y(0) = -1','Dy(0) = 2')

Output:
y =exp(t)/2 - (3*exp(-t))/2

2 x
Example 5: Solve ( D +5 D+6) y=e
y=dsolve('D2y+5*Dy+6*y=exp(x)','x')

Output:
y=
exp(x)/12 + C25*exp(-2*x) + C26*exp(-3*x)

2 −x
Example 6. Solve ( D +5 D+6) y=4 e log x

y=dsolve('D2y+5*Dy+6*y=4*exp(-x)*log(x)','x')

Output:
y=
C28*exp(-2*x) - exp(-2*x)*(4*ei(x) - 4*exp(x)*log(x)) + C29*exp(-3*x) +
exp(-3*x)*(2*ei(2*x) - 2*exp(2*x)*log(x))

3 2 x ' ''
Example 4. Solve ( D −D +D−1) y=e +cos x , y (0 )= y (0 )= y (0 )=0
y=dsolve('D3y-D2y+Dy-y=exp(x)
+cos(x)','y(0)=0','Dy(0)=0','D2y(0)=0','x')

TASK :8

1. Solve
( dy
dt ) −t
+4 y (t )=e , y (0 )=1 .

PROGRAM:
syms x;
y=dsolve('Dy+4*y=exp(-t)','t')

OUTPUT:
y=
exp(-t)/3 + (2*exp(-4*t))/3

dy
− y cot x=2 x sin x
2. Solve dx

PROGRAM:
syms x;
y=dsolve('Dy-y*cot(y)=2*x*sin(x)')
OUTPUT:
y=
x^2sin(x)+C1*sin(x)

( D2−D+1 ) y=0
3. Solve the differential equation
PROGRAM:
y=dsolve('D2y-Dy+1=0','x')

OUTPUT:
y=
C1 + x + C2*exp(x) + 1

. Solve the differential equation


( D3 −3 D2 +3 D−1 ) y=0
4

PROGRAM:
y=dsolve('D3y-3*D2y+3*Dy-y=0','x')

OUTPUT:
y=

C1*exp(x) + C3*x^2*exp(x) + C2*x*exp(x)

. Solve the differential equation


( D 4
−2 D 2
+1 ) y=0
5

PROGRAM:
y=dsolve('D4y-2*D2y+y=0','x')

OUTPUT:
y=
C3*exp(x) + C1*exp(-x) + C2*x*exp(-x) + C4*x*exp(x)
4 3 2 2 x
( D −2 D +D ) y=x +e
6. Solve the differential equation

PROGRAM:

y=dsolve('D4y-2*D3y+D2y=x^2+exp(x)','x')

OUTPUT:

y=

C18*exp(x) - C17 - (x^2*exp(x))/2 - (x^2*(12*C16 - 60))/12 - (x*(24*x - 12*C17 -


12*C16 - 12*C16*x - 12*x*exp(x) + 12*x^2 + 4*x^3 + x^4 + 24))/12 - (x*(24*C16
+ 12*C17 - 120))/12 - 2*C16 + (5*x^3)/3 + (5*x^4)/12 + x^5/12 + C19*x*exp(x) +
10

2 −x
( D+1) y=e cos x
7. Solve the differential equation

PROGRAM:

y=dsolve('D2y+2*Dy+y=exp(-x)*cos(x)','x')

OUTPUT:

y=

C1*exp(-x) - exp(-x)*(cos(x) + x*sin(x)) + C2*x*exp(-x) + x*exp(-x)*sin(x)

( D2 +4) y=cos 3 x
8. Solve the differential equation

PROGRAM:
y=dsolve('D2y+4*y=cos(3*x)','x')

OUTPUT:
y=
C1*cos(2*x) - C2*sin(2*x) + sin(2*x)*(sin(5*x)/20 + sin(x)/4) - (2*cos(2*x)*(10*tan(x/2)^2
- 20*tan(x/2)^4 + 30*tan(x/2)^6 - 5*tan(x/2)^8 + 1))/(5*(tan(x/2)^2 + 1)^5)

WORKSHEET- 9
DETERMINING MAXIMA AND MINIMA OF A FUNCTION OF ONE
VARIABLE
9.1OBJECTIVE
 To determine the maxima and minima of a function of a single variable
9.2Example 1:Find the extreme value of the function f(x)= x3 – 12x2 – 20.
Program:
syms x
f=x^3-12*x^2-20
fx=diff(f,x)
a=solve(fx)
double(a)
fxx=diff(fx,x)
D=subs(fxx,x,8)
if D >0
disp('Attains Minima')
else
disp('Attains Maxima')
end
D=subs(fxx,x,0)
if D >0
disp('Attains Minima')
else
disp('Attains Maxima')
end
OUTPUT
f =x^3 - 12*x^2 - 20
fx = 3*x^2 - 24*x
a =08
fxx = 6*x - 24
D = 24 D=-24
Attains MinimaAttains Maxima
Task:9
4 3
f (x )=x −5 x +3 x−18
1.Find the maximum value of the function

3 2
f (x )=7 x −2 x −5
2. Find the minimum value of the function
3 2
f (x )=x −3 x −24 x +5
3. Find the extrema of the function

f (x )=x (12−2 x )2
4. Find the extrema of
WORKSHEET- 10
DETERMINING MAXIMA AND MINIMA OF A FUNCTION OF TWO VARIABLES

10.1 OBJECTIVES
 To determine maxima and minima of a function of two variables.
10.2Example 1: Find the extreme value of the function

f (x , y )=x 4 +2 y 4 −12 xy 2 −20 y 2 . (1,2)(1, 4)

PROGRAM:
syms x y
f=x.^4+2*y.^4-12*x*y.^2-20*y.^2
fx=diff(f,x)
fy=diff(f,y)
[a,b]=solve(fx,fy);
double([a,b])
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
D=fxx*fyy-(fxy)^2
D1=subs(D,[x,y],[3.6247,3.9842])
A1=subs(fxx,[x,y],[3.6247,3.9842])
D2=subs(D,[x,y],[3.6247,-3.9842])
A2=subs(fxx,[x,y],[3.6247,-3.9842])
if D1>0
if A1>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D1==0
disp('No conclusion')
else
disp('Neither Minima nor Maxima')
end
end
if D2>0
if A2>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D2==0
disp('no conclusion')
else
disp('Neither Minima nor maxima')
end
end
ezsurf(f,[0,5,0,5])

Output:
f =x^4 - 12*x*y^2 + 2*y^4 - 20*y^2
fx = 4*x^3 - 12*y^2
fy = 8*y^3 - 24*x*y - 40*y
ans =
0.0000 + 0.0000i 0.0000 + 0.0000i
3.6247 + 0.0000i 3.9842 + 0.0000i
3.6247 + 0.0000i -3.9842 + 0.0000i
-1.8123 - 0.9240i 1.0884 - 1.2734i
-1.8123 + 0.9240i 1.0884 + 1.2734i
-1.8123 - 0.9240i -1.0884 + 1.2734i
-1.8123 + 0.9240i -1.0884 - 1.2734i
fxx =12*x^2
fxy = -24*y
fyy = 24*y^2 - 24*x - 40
D = - 12*x^2*(- 24*y^2 + 24*x + 40) - 576*y^2
ans =
3941535027/25000000

x4 - 12 x y2 - 20 y2 + 2 y4

600

400

200

-200

5
4 5
3 4
2 3
2
1 1
y 0 0
x

Example 2 :. Find the extreme value of the function


3 3 2 2
f (x , y )=x +2 y −12 xy −20 y

Program:
syms x y
f=x.^3+2*y.^3-12*x*y.^2-20*y.^2
fx=diff(f,x)
fy=diff(f,y)
[a,b]=solve(fx,fy);
double([a,b])
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
D=fxx*fyy-(fxy)^2
D1=subs(D,[x,y],[-1.4815,0.7807])
A1=subs(fxx,[x,y],[-1.4815,0.7807])
D2=subs(D,[x,y],[-1.9048,-0.9524])
A2=subs(fxx,[x,y],[-1.9048,-0.9524])
if D1>0
if A1>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D1==0
disp('No conclusion')
else
disp('Neither Minima nor Maxima')
end
end
if D2>0
if A2>0
disp('Attains Minima')
else
disp('Attains Maxima')
end
else
if D2==0
disp('no conclusion')
else
disp('Neither Minima nor maxima')
end
end
ezsurf(f,[0,5,0,5])

Output:
f =x^3 - 12*x*y^2 + 2*y^3 - 20*y^2
fx =3*x^2 - 12*y^2
fy =6*y^2 - 24*x*y - 40*y
ans =
0 0
-1.9048 -0.9524
-1.4815 0.7407

fxx =6*x
fxy =-24*y
fyy =12*y - 24*x - 40
D =- 576*y^2 - 6*x*(24*x - 12*y + 40)
D1=-4935508323/12500000
A1 =-8889/1000
D2 =-178582143/390625
A2 =7143/625

Neither Minima nor Maxima


Neither Minima nor maxima
Task :10
3 2
1. Find the Maximum value of the function f (x , y )=x −3 xy −12 xy +2
4 3
f (x , y )=x +6 y −36 xy−20 y
2. Find the Minimum value of the function

4 4 2 2
u( x , y )=x + y −2 x +4 xy−2 y
3. Examine for extreme values of the function
4. Find the maximum and minimum values of the function
f (x , y )=x 3 + y 3 −63( x+ y )+12 xy
5. Find the maximum or minimum value of the function
f (x , y )=2( x 2 − y 2 )−x 4 + y 4

You might also like