Quadratic numbers in matlab
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 !
0 Kommentare
Antworten (1)
Nalini Vishnoi
am 20 Mai 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);
end
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);
I hope this helps.
Nalini
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!