Open In App

Conversion of Quadratic Form to Canonical Form in MATLAB

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  

Then, , 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):

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:

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:

Example:

% 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:

 


Article Tags :