How to separate negative and positive terms in to two different expressions
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
I am using symolic vavriables 
syms a b c d f g
Where all syms variables are positive
and have, for example the following expression A
F=a- b*d+ g*c-a*c+ d*g
my actual expression is much longer but how can I separate the negative vs the positive terms and put them in say in x and y?
I appreciate any help .
Thank you!
댓글 수: 0
채택된 답변
  Ameer Hamza
      
      
 2020년 12월 3일
        Try this
syms a b c d f g
F = a - b*d + g*c - a*c + d*g;
parts = children(F);
parts = [parts{:}];
assume(symvar(parts)>0)
sgns = sign(parts);
assume(symvar(parts), 'clear')
x = parts(sgns==1);
y = parts(sgns==-1);
댓글 수: 4
  Ameer Hamza
      
      
 2020년 12월 3일
				Yes, it seems something related to old release. It seems that children() does not return a cell array in your case.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Numbers and Precision에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

