MATLAB: Simplifying symbolic expression in terms of other variables

simplificationsymbolic

This is a simplified problem to illustrate what I need: Given the symbolic expression a^2+b^2+2ab+a+b+1 and the definition x=a+b how do I simplify the symbolic expression to give the answer in terms of x, i.e. x^2+x+1?
I've played around with the symbolic toolbox without success.

Best Answer

You could also try
syms a b x
assume(x== a+b);
F = a^2+b^2+2*a*b+a+b+1;
simplify(F)