help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fixing a number at a certain precission?


From: veryhappy
Subject: Re: Fixing a number at a certain precission?
Date: Fri, 4 Mar 2011 00:11:54 -0800 (PST)

Thanks for your interest. I'll post a fragment of code similar to what i'm
working on when i get the error:

function prueba()
  w_0=1000*2*pi;
  den=[0,1,1;1,1,1];
  % I calculate the roots of each polynomial of den into r_den_norm and
  % then I make an order 1 polynomial from them
  r_den_norm=cell2mat(arrayfun(@(x)
roots(den(x,:)),1:size(den),"UniformOutput",false)');
  poly_norm=[ones(length(r_den_norm),1),-r_den_norm];
  
  % Then I process them to get order 2 polynomials
  temp_den=[poly_norm(:,2),...
            poly_norm(:,1)*w_0,...
            poly_norm(:,2)*w_0^2];
  
  % And last I get the roots of each order 2 polynomials, which are
  % complex conjugated pairs, and pair them
  r_unnorm=cell2mat(arrayfun(@(x)
roots(temp_den(x,:)),1:size(temp_den),"UniformOutput",false)');
  cplxpair(r_unnorm(3:end)); % This make no error
  
  
  %cplxpair(r_unnorm(1:2)) % This one throw an error but...
  
  
  % I'll do that process only for the conflicting one
  % Getting the root (It's a order 1 polynomial
  r_den_norm2=roots(den(1,:));
  % Remaking the polynomial
  poly_norm2=[1,-r_den_norm2];
  % Processing to get the order 2 polynomial
  temp_den2 =[poly_norm2(1,2),...
              poly_norm2(1,1)*w_0,...
              poly_norm2(1,2)*w_0^2];
  % Getting the order 2 polynomial's roots
  r_unnorm2=roots(temp_den2);
  % And pairing them
  cplxpair(r_unnorm2) % Gives no error
endfunction

As you can see from the last part the polynomial with real coefficients
itself doesn't have a weird behavior but, as you see in the first part, when
i mix it with polynomials with imaginary parts then i've the problem i'm
willing to solve (Note that the conflicting polynomial is the one with real
coefficients and that the ones with imaginary coefficients are well paired)

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Fixing-a-number-at-a-certain-precission-tp3333384p3334831.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]