Quadratic numbers in matlab

1 view (last 30 days)
Mayur Punekar
Mayur Punekar on 18 May 2015
Commented: Mayur Punekar on 24 May 2015
I inverted a matrix H with entries from quadratic field, e.g., Q(sqrt(3)) and the inverted matrix G gives me entries also from Q(sqrt(3)), e.g., entry at (1,1) is 12 - 8*3^(1/2). However, is there a way to decouple integer coefficient 12 and -8? I want to store these integer values separately.
In fact I want to generate two integer matrices G1 and G2 from G which contains integer coefficients of each entry in G.
Can anyone suggest how can I do it??
Thanks in advance !

Answers (1)

Nalini Vishnoi
Nalini Vishnoi on 20 May 2015
Hi Mayur,
I can think of one way to do what you asked by using Symbolic Math toolbox. It has a function coeffs which can return the coefficients of a polynomial. I have included a small example below demonstrating how to do it.
syms x; % Create a symbolic variable
G = repmat(12-8*x, 10,2); % Create a matrix of polynomials
for i = 1:size(G,2), % Use coeffs column by column
[C(:,i)] = arrayfun(@(z) coeffs(z,x), G(:,i),'Uniformoutput', false);
G1 = cellfun(@(x) double(x(1)), C, 'UniformOutput', false); % extract the coefficients as doubles
G1 = cell2mat(G1); % Convert the cell to a matrix
G2 = cellfun(@(x) double(x(2)), C, 'UniformOutput', false);
G2 = cell2mat(G2);
Please note that you can use subs to substitute symbolic variable 'x' with sqrt(3).
I hope this helps.
  1 Comment
Mayur Punekar
Mayur Punekar on 24 May 2015
Hello Nalini,
Thanks for the reply but unfortunately it didn't solve my problem.
I state my problem more explicitly here. I have a matrix H which has entries from quadratic field Q(3^(1/2)) i.e., entries are in form of h(i,j) = a+b*3^(1/2), where a,b are integers.
H = [0, 0, 1/x, 0, 0, 1/x, 0, 1; 1/x, 0, 0, 0, 0, 1, 0, 1/x; 0, 0, 1, 1/x, 0, 0, 1/x, 0; 0, 1/x, 0, 1, 1/x, 0, 0, 0; 1/x, 1, 0, 0, 0, 1/x, 0, 0; 0, 1/x, 0, 0, 1/x, 0, 1, 0; 0, 0, 0, 1/x, 1, 0, 0, 1/x; 1, 0, 1/x, 0, 0, 0, 1/x, 0];
Now I want to invert this matrix in such a way that the inverted matrix G still has entries of the form G(i,j) = a+b*3^(1/2).
As far as I know, theory suggests that any matrix with entries in Q(3^(1/2)) (or in general Q(D^(1/2)) can be inverted so that the inverted matrix also contains entries from the same field.
I tried many methods but couldn't find a way to get desired results with matlab. Can you suggest a method to solve this problem?
Thanks !

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!