Open In App

Conversion of Quadratic Form to Canonical Form in MATLAB

Last Updated : 08 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The quadratic form is a Homogeneous polynomial of second degree in any number of variables. In this article we will see, Conversion of the Quadratic Form to the Canonical Form.

For Example, 

if A = \begin{bmatrix} a &  h& g \\ h &b  &f  \\ g& f &c  \\ \end{bmatrix} X = \begin{bmatrix} x \\ y\\ z\\ \end{bmatrix} X` = \begin{bmatrix} x \\ y\\ z\\ \end{bmatrix}    

Then, X`AX = ax^{2}  + by^{2} + cz^{2} + 2fyz + 2gxz + 2hxy  , Which is a Quadratic Form.

Every Quadratic form can be reduced to a sum of squares, called as Canonical Form:

λ1x2 + λ2y2 + λ3z2, 
Where λ1, λ2 & λ3 are Eigen Values of the above 
Matrix 'A' (Matrix of Quadratic form)

Steps to Convert Quadratic form to Canonical form:

Step 1: Consider that the given Quadratic form is in the following format:

ax2+by2+cz2+2fyz+2gxz+2hxy

Step 2:  Then from the above Quadratic form, we find the below matrix ‘A’ (called as Matrix of Quadratic form):
A = [a,h,g; h,b,f; g,f,c]

Step 3:  After finding the above Matrix “A”, we find the Eigenvalues of it by solving its Characteristic Equation. The Characteristic Equation of ‘A’ is:

|A-λI3| = 0, 
Where I3 is the Identity Matrix of order 3.

Step 4:  Expanding the above relation, we get:

λ3 + C1λ2 + C2λ + C3I3 = 0, 
where C1, C2 & C3 are Real Constants.

Step 5: Solving the above relation, we get 3 Solutions for ‘λ’, let the 3 Solutions be λ1, λ2 & λ3.

Step 6: Then the Canonical form of the given Quadratic form (ax2+by2+cz2+2fyz+2gxz+2hxy) is represented as:

Canonical Form = λ1x2 + λ2y2 + λ3z2 

Different Parameters associated with Quadratic form are:

  • Index: It is the Number of Positive Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form). The Index of the Quadratic form can also be defined as the number of Positive square terms in the Canonical form representation of the Quadratic form.
  • Signature: It is the difference between the Number of Positive and Negative Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form). The Signature of the Quadratic form can also be defined as the difference between the Number of Positive and Negative square terms in the Canonical form representation of the Quadratic form.
  • Rank: It is the number of non-zero Eigenvalues of the Matrix ‘A’ (Matrix of Quadratic form). The Rank of the Quadratic form can also be defined as a number of non-zero rows in the row echelon form of the matrix ‘A’.
  • Nature of Quadratic form: Based on the Nature of the Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form), The Nature of the Quadratic Form is decided.
    • If all the Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form) are Positive, then the Nature of Quadratic form is said to be Positive Definite.
    • Else If all the Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form) are Negative, then the Nature of Quadratic form is said to be Negative Definite.
    • Else If all the Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form) are non-negative, then the Nature of Quadratic form is said to be positive semidefinite.
    • Else If all the Eigenvalues of Matrix ‘A’ (Matrix of Quadratic form) are non-positive, then the Nature of Quadratic form is said to be Negative semidefinite.
    • Else in all the other cases (Mix of Positive, Negative & Zero Eigenvalues of ‘A’), The Nature of the Quadratic form is said to be “Indefinite”.

Note: Here, a non-negative Eigenvalue means it can either be Zero or a positive valve. Also, a non-positive Eigenvalue means it can be either be Zero or a negative valve.

MATLAB Functions used in the Below Code are:

  • disp(“txt”): This Method displays the message-“txt” to the User.
  • input(“txt”): This Method displays the message-“txt” and waits for the user to input a value and press the Return key.
  • eig(A): This method returns a column vector containing the Eigenvalues of the Square matrix ‘A’.
  • strcat(A, B,…): This Method horizontally concatenates the text in its input arguments.
  • rank(A): This method returns the rank of the matrix ‘A’. 

Example:

Matlab

% MATLAB Implementation to convert Quadratic Form
% to Canonical Form and to find Different Parameters
% associated with Quadratic form:
 clear all 
 clc        
 disp("MATLAB Implementation to convert Quadratic Form to
     Canonical Form and to find Different Parameters associated
     with Quadratic form | GeeksforGeeks")
E = input("Enter the coefficients in the order 
   [a,b,c,f,g,h] for the Quadratic form: [ax^2+by^2+cz^2+2fyz+2gxz+2hxy] : ");
a = E(1);
b = E(2); 
c = E(3);
  
% Coefficients of the Quadratic form
f = E(4); g=E(5); h=E(6);  
  
% Finding Matrix 'A' (Matrix of Quadratic form) 
e = eig(A);
A = [a h g;h b f;g f c];  
  
% λ1 , λ2 & λ3
l1 = e(1);
l2 = e(2);
l3 = e(3); 
  
disp(strcat('The Canonical form of given Quadratic form is: 
(',num2str(l1),')x^2+(',num2str(l2),')y^2+(',num2str(l3),')z^2'))
a=0;
b=0;
  
% Counting the Number of Positive and Negative Eigen 
% values of Matrix 'A' (Matrix of Quadratic form) 
for i=1:3    
    if(e(i)>0)
        a=a+1;
    elseif(e(i)<0)
        b=b+1;
    end
end
  
% Number of Positive Eigen values of Matrix 
% 'A' (Matrix of Quadratic form) 
index=a
  
% Difference between the number of Positive and Negative 
% Eigen values of Matrix 'A' (Matrix of Quadratic form) 
  
signature=a-b  
rank=rank(A)
 % If all Eigen values of Matrix 'A'
 % (Matrix of Quadratic form) are Positive
   
if(a==3)           
    disp('The Nature of given Quadratic form is Positive Definite')
% If all Eigen values of Matrix 'A' 
% (Matrix of Quadratic form) are Negative
  
elseif(b==3)       
    disp('The Nature of given Quadratic form is Negative Definite')
% If all Eigen values of Matrix 'A' (Matrix of Quadratic form) 
% are non-negative (positive or zero)
  
elseif(b==0)        
    disp('The Nature of given Quadratic form is Positive Semi-Definite')
% If all Eigen values of Matrix 'A' (Matrix of Quadratic
% form) are non-positive (negative or zero)
  
elseif(a==0)        
    disp('The Nature of given Quadratic form is Negative Semi-Definite')
else                
% If all Eigen values of Matrix 'A' (Matrix of 
% Quadratic form) are Mix of Positive, Negative & Zero
  
    disp('The Nature of given Quadratic form is InDefinite')
end

                    
input: If the Quadratic form is x2+3y2+3z2-2yz

Output:

 

Input: If the Quadratic form is 2yz+2xz-2xy

Output:

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads