FindFactors

by

 

Find factors of a symbolic expression. It generalizas coeffs for non polinomials

[Factors,Res]=FindFactors(Term,Vector);
function [Factors,Res]=FindFactors(Term,Vector);
Res=sym(0);
for k=1:length(Vector)
    A1=coeffs(Term,Vector(k));
    Test1=simplify(A1(1)-Term,5);
    if Test1==0
        Factors(k)=sym(0);
    else if length(A1)==1
            Factors(k)=simplify(A1,'Seconds',0.5);
        else
            %exp=A1(2)
            %simplify(exp,10)
            Factors(k)=simplify(A1(2),'Seconds',0.5);
        end
    end
end
Term_Simple=Factors*Vector.';
Test=simplify(Term-Term_Simple,5);
if ne(Test,0)
    Res=Test;
%     if length(char(Test)) > 10
%         disp('El Termino TERM no contiene solo factores de los elementos de VECTOR; Contiene ademas:');
%         s=sprintf('%s',char(Test));
%         disp(s);
%     else
%         s=sprintf('El Termino TERM no contiene solo factores de los elementos de VECTOR; Contiene ademas:%s',char(Test));
%         disp(s);        
%     end
end

Contact us