Polynomial to Matrix form(canonical form)

8 views (last 30 days)
How to convert the given quadratic form(Q = x1^2 + 2x1x2+x2^2) into its canonical form in matlab.
  5 Comments
Walter Roberson
Walter Roberson on 19 Aug 2020
https://www.mathworks.com/matlabcentral/answers/445266-polynomial-to-matrix-form-canonical-form#answer_470380

Sign in to comment.

Answers (3)

lalith keerthan
lalith keerthan on 24 Jul 2020
syms x1 x2 x3 y1 y2 y3 a b c p
Q=input('Enter the form in x1 x2 x3')
a11=(1/2)*diff(diff(Q,x1),x1)
a22=(1/2)*diff(diff(Q,x2),x2)
a33=(1/2)*diff(diff(Q,x3),x3)
a12=(1/2)*diff(diff(Q,x1),x2)
a21=a12
a13=(1/2)*diff(diff(Q,x1),x3)
a13=a31
a23=(1/2)*diff(diff(Q,x2),x3)
a23=a23
A=[a11,a12,a13;a21,a22,a23;a31,a32,a33]
[N D]=eig(A)
X=[x1,x2,x3]
Y=[y1,y2,y3]
disp(D(1,1)*y1^2+D(2,2)*y2^2+D(3,3)*y3^2)
[m,n]=size(A);
for i=1:n
N(:,i)=[N(1,i)/sqrt(N(1,i)^2+N(2,i)^2+N(3,i)^2) N(2,i)/sqrt(N(1,i)^2+N(2,i)^2+N(3,i)^2) N(3,i)/sqrt(N(1,i)^2+N(2,i)^2+N(3,i)^2)]
end
display('no repeated eigen value and the orthogonal transformation is X=NY')
X==(N*Y)
  2 Comments
Walter Roberson
Walter Roberson on 24 Jul 2020
Is that a question or a solution to the poster's question ?
John D'Errico
John D'Errico on 24 Jul 2020
Edited: John D'Errico on 24 Jul 2020
I think it was an attempt at an answer/ At least it started out as one, sort of. But things got lost along the way, following a convoluted, confused path at the end.

Sign in to comment.


John D'Errico
John D'Errico on 24 Jul 2020
Edited: John D'Errico on 24 Jul 2020
I assume the question is to resolve a quadratic polynomial, perhaps:
Q = x1^2 + 2*x1*x2 + x2^2
into a quadratic form. That is, given Q, you want to recover the matrix H, such that
Q = [x1,x2]*H*[x1;x2]
This is quite easy using the symbolic toolbox. The desired matrix H is 1/2 times the Hessian matrix of Q.
For example, given the quadratic Q...
syms x1 x2
Q = x1^2 + 2*x1*x2 + x2^2
Q =
x1^2 + 2*x1*x2 + x2^2
X = [x1,x2];
H = hessian(Q)/2
H =
[ 1, 1]
[ 1, 1]
H is the desired matrix. We can see Q is recovered:
expand(X*H*X.')
ans =
x1^2 + 2*x1*x2 + x2^2
This is just an educated guess on my part as to the answer. Since there has been no response from the OP since it as first posted, we can only guess.
  2 Comments
Gaurav Malik
Gaurav Malik on 23 Aug 2021
Yeah but what do you do when you also have linear terms in your function? We need also the c'X term.
Walter Roberson
Walter Roberson on 23 Aug 2021
In such a case are you working with a quadratic form ? Are you, as John indicates, trying to recover the H in Q = [x1,x2]*H*[x1;x2] ?

Sign in to comment.


Walter Roberson
Walter Roberson on 16 Feb 2019
syms x1 x2
QQ = x1^2 +2*x1*x2+x2^2
factor(QQ)

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!