Quadratic numbers in matlab
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Nalini Vishnoi
2015-5-20
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
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!