https://github.com/janverschelde/PHCpack
Raw File
Tip revision: 6e8f04d9358f87fec2bd9f501e37f34645f0b2ff authored by janv@uic.edu on 01 May 2016, 01:55:44 UTC
added function to filter real solutions to the python2 version of phcpy, prepared version 0.4.4 of phcpy
Tip revision: 6e8f04d
modify_poly.m
function [mf]=modify_poly(f)
%
% [mf]=modify_poly(f)
% Taking only the real part of the complex coefficients
% of the given polynomial f
%
start = findstr(f,'(');
finish = findstr(f,')');
start_var = finish+1;
finish_var = start-2;
num_coeff = size(start,2);
coeffs = cell(num_coeff,1);
vars = cell(num_coeff-1,1);
for k=1:num_coeff
   temp = f(start(k)+1:finish(k)-1);
   coeffs{k} = real(str2num(temp)); % take the real part
   if (k<=num_coeff-1)
      vars{k} = f(finish(k)+1:start(k+1)-2);
  end
end
% form the new polynomial
mf = blanks(0);
for k=1:num_coeff
    if(k<=num_coeff-1)
       if(coeffs{k}<0)
          mf = [mf num2str(coeffs{k},'%16.14e') vars{k}];
       else % positive coeff.
          mf = [mf '+' num2str(coeffs{k},'%16.14e') vars{k}];
      end
    else
      if(coeffs{k}<0)
          mf = [mf num2str(coeffs{num_coeff},'%16.14e')];
      else
          mf = [mf '+' num2str(coeffs{num_coeff},'%16.14e')];
      end
    end
end



back to top