[go: up one dir, main page]

0% found this document useful (0 votes)
530 views9 pages

Cayley Hamilton Theorem: Source Code

The document contains MATLAB source code to verify Cayley Hamilton theorem and diagonalize matrices. It defines symbolic variables, finds the characteristic polynomial, calculates the inverse and powers of matrices using Cayley Hamilton theorem, and diagonalizes matrices by finding the eigen values and constructing the transformation matrix. The code is run on different 3x3 matrices and outputs the verification, inverse, powers and diagonalization each time to demonstrate the concepts.

Uploaded by

Srinath
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)
530 views9 pages

Cayley Hamilton Theorem: Source Code

The document contains MATLAB source code to verify Cayley Hamilton theorem and diagonalize matrices. It defines symbolic variables, finds the characteristic polynomial, calculates the inverse and powers of matrices using Cayley Hamilton theorem, and diagonalizes matrices by finding the eigen values and constructing the transformation matrix. The code is run on different 3x3 matrices and outputs the verification, inverse, powers and diagonalization each time to demonstrate the concepts.

Uploaded by

Srinath
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/ 9

CAYLEY HAMILTON THEOREM

Aim:

To write a MATLAB program to verify Cayley Hamilton theorem for the matrix Also

compute and using Cayley Hamilton Theorem.

Main Commands:
syms - to define symbolic variables and fynctions

charpoly - to create the characteristic polynomial

format rational - to create numbers in the rational form

Source Code:

syms A s
A=[7 2 -2; -6 -1 2; 6 2 -1];
I=[1 0 0; 0 1 0; 0 0 1];
charpoly(A,s)==0

ans =

verification=A^3-5*A^2+7*A-3*I

verification = 3×3
0 0 0
0 0 0
0 0 0

format rational
inv_A=(1/3)*(A^2-5*A+7*I)

inv_A =
-1 -2/3 2/3
2 5/3 -2/3
-2 -2/3 5/3

A_power4=5*A^3-7*A^2+3*A

A_power4 =
241 80 -80
-240 -79 80
240 80 -79

Aim:

To write a MATLAB program to verify Cayley Hamilton theorem for the matrix Also compute

and using Cayley Hamilton Theorem.

Main Commands:

1
syms - to define symbolic variables and fynctions

charpoly - to create the characteristic polynomial

format rational - to create numbers in the rational form

Source Code:

syms A s
A=[2 1 1; 0 1 0; 1 1 2];
I=[1 0 0; 0 1 0; 0 0 1];
charpoly(A,s)==0

ans =

verification=A^3-5*A^2+7*A-3*I

verification =
0 0 0
0 0 0
0 0 0

format rational
inv_A=(1/3)*(A^2-5*A+7*I)

inv_A =
2/3 -1/3 -1/3
0 1 0
-1/3 -1/3 2/3

A_power4=5*A^3-7*A^2+3*A

A_power4 =
41 40 40
0 1 0
40 40 41

Aim:

To write a MATLAB program to verify Cayley Hamilton theorem for the matrix Also compute

and using Cayley Hamilton Theorem.

Main Commands:
syms - to define symbolic variables and fynctions

charpoly - to create the characteristic polynomial

format rational - to create numbers in the rational form

Source Code:

syms A s
A=[-2 2 -3; 2 1 -6; -1 -2 0];
I=[1 0 0; 0 1 0; 0 0 1];
charpoly(A,s)==0

2
ans =

verification=A^3+A^2-21*A-45*I

verification =
0 0 0
0 0 0
0 0 0

format rational
inv_A=(1/45)*(A^2+A-21*I)

inv_A =
-4/15 2/15 -1/5
2/15 -1/15 -2/5
-1/15 -2/15 -2/15

A_power4=-A^3+21*A^2+45*A

A_power4 =
149 136 -204
136 353 -408
-68 -136 285

Aim:

To write a MATLAB program to verify Cayley Hamilton theorem for the matrix Also compute

and using Cayley Hamilton Theorem.

Main Commands:
syms - to define symbolic variables and fynctions

charpoly - to create the characteristic polynomial

format rational - to create numbers in the rational form

Source Code:

syms s
A=[1 1 3; 1 3 -3; 2 -4 -4];
I=[1 0 0; 0 1 0; 0 0 1];
charpoly(A,s)==0

ans =

verification=A^3-32*A+56*I

verification =
0 0 0
0 0 0
0 0 0

format rational
inv_A=(1/56)*(-A^2+32*I)

3
inv_A =
3/7 1/7 3/14
1/28 5/28 -3/28
5/28 -3/28 -1/28

A_power4=32*A^2-56*A

A_power4 =
200 -312 -552
-120 536 360
-432 416 1312

DIAGONALIZATION OF MATRICES
Aim:

To write a MATLAB program to diagonalize the matrix

Main Commands:
syms - to define symbolic variables and fynctions

eig - to get the eigen values

disp - to display the things

format rational - to create numbers in the rational form

Source Code:

syms s
A =[1 1 3;1 5 1;3 1 1]

A =
1 1 3
1 5 1
3 1 1

charpoly(A,s)==0

ans =

eig(A)

ans =
-2
3
6

[N D]= eig (A);


M(: ,1)=N(: ,1)* sqrt (2) ;
M(: ,2)=N(: ,2)* sqrt (3) ;
M(: ,3)=N(: ,3)* sqrt (6)

M =

4
-1 1 1
* -1 2
1 1 1

[N D]= eig (A)

N =
-985/1393 780/1351 881/2158
* -780/1351 881/1079
985/1393 780/1351 881/2158
D =
-2 0 0
0 3 0
0 0 6

Aim:

To write a MATLAB program to diagonalize the matrix

Main Commands:
syms - to define symbolic variables and fynctions

eig - to get the eigen values

disp - to display the things

format rational - to create numbers in the rational form

Source Code:

syms s
A =[2 1 -1; 1 1 -2; -1 -2 1]

A =
2 1 -1
1 1 -2
-1 -2 1

charpoly(A,s)==0

ans =

eig(A)

ans =
-1
1
4

[N D]= eig (A);


M(: ,1)=N(: ,1)* sqrt (2) ;
M(: ,2)=N(: ,2)* sqrt (3) ;
M(: ,3)=N(: ,3)* sqrt (6)

M =

5
* 1393/985 -1393/985
1 -985/1393 -1393/985
1 985/1393 1393/985

[N D]= eig (A)

N =
* 881/1079 -780/1351
985/1393 -881/2158 -780/1351
985/1393 881/2158 780/1351
D =
-1 0 0
0 1 0
0 0 4

Aim:

To write a MATLAB program to diagonalize the matrix

Main Commands:
syms - to define symbolic variables and fynctions

eig - to get the eigen values

disp - to display the things

format rational - to create numbers in the rational form

Source Code:

syms s
A =[2 1 -1; 1 1 -2; -1 -2 1]

A =
2 1 -1
1 1 -2
-1 -2 1

charpoly(A,s)==0

ans =

eig(A)

ans =
-1
1
4

[N D]= eig (A);


M(: ,1)=N(: ,1)* sqrt (2) ;
M(: ,2)=N(: ,2)* sqrt (3) ;
M(: ,3)=N(: ,3)* sqrt (6)

M =

6
* 1393/985 -1393/985
1 -985/1393 -1393/985
1 985/1393 1393/985

[N D]= eig (A)

N =
* 881/1079 -780/1351
985/1393 -881/2158 -780/1351
985/1393 881/2158 780/1351
D =
-1 0 0
0 1 0
0 0 4

Aim:

To write a MATLAB program to diagonalize the matrix

Main Commands:
syms - to define symbolic variables and fynctions

eig - to get the eigen values

disp - to display the things

format rational - to create numbers in the rational form

Source Code:

syms s
A =[3 -1 1; -1 5 -1; 1 -1 3]

A =
3 -1 1
-1 5 -1
1 -1 3

charpoly(A,s)==0

ans =

eig(A)

ans =
2
3
6

[N D]= eig (A);


M(: ,1)=N(: ,1)* sqrt (2) ;
M(: ,2)=N(: ,2)* sqrt (3) ;
M(: ,3)=N(: ,3)* sqrt (6)

M =

7
1 -1 1
* -1 -2
-1 -1 1

[N D]= eig (A)

N =
985/1393 -780/1351 881/2158
* -780/1351 -881/1079
-985/1393 -780/1351 881/2158
D =
2 0 0
0 3 0
0 0 6

Aim:

To write a MATLAB program to diagonalize the matrix

Main Commands:
syms - to define symbolic variables and fynctions

eig - to get the eigen values

disp - to display the things

format rational - to create numbers in the rational form

Source Code:

syms s
A =[2 0 4; 0 6 0; 4 0 2]

A =
2 0 4
0 6 0
4 0 2

charpoly(A,s)==0

ans =

eig(A)

ans =
-2
6
6

[N D]= eig (A);


M(: ,1)=N(: ,1)* sqrt (2) ;
M(: ,2)=N(: ,2)* sqrt (3) ;
M(: ,3)=N(: ,3)* sqrt (6)

M =

8
1 1079/881 0
0 0 -2158/881
-1 1079/881 0

[N D]= eig (A)

N =
985/1393 985/1393 0
0 0 -1
-985/1393 985/1393 0
D =
-2 0 0
0 6 0
0 0 6

You might also like