4

I'm trying to simplify some symbolic equations.

>> syms x;
>> simplify(sqrt(x^2)/x)

ans =

(x^2)^(1/2)/x

Actually, I want matlab to return 1 or smth like that.

>> simplify((x^9+7*x^8-2*x-6)/(x-1))

ans =

-(- x^9 - 7*x^8 + 2*x + 6)/(x - 1)

1 is a root of numerator, so I want matlab to reduce that fraction.

What am I doing wrong?

Amro
  • 123,847
  • 25
  • 243
  • 454

2 Answers2

3

Answer for the first question is simple.

>> x = sym('x', 'positive' )

x =

x

>> simplify(sqrt(x^2)/x)

ans =

1
3

For the second question, you might have to help show Matlab the way:

>> factor(x^9+7*x^8-2*x-6)

ans =

(x - 1)*(x^8 + 8*x^7 + 8*x^6 + 8*x^5 + 8*x^4 + 8*x^3 + 8*x^2 + 8*x + 6)

>> ans/(x-1)

ans =

x^8 + 8*x^7 + 8*x^6 + 8*x^5 + 8*x^4 + 8*x^3 + 8*x^2 + 8*x + 6
nibot
  • 14,428
  • 8
  • 54
  • 58