The ‘collect()’ command is a very useful command that you can easily rearrange polynomials and equations in Matlab®. Here, we explain how to do it with a very basic example that is executed in the command window of Matlab®.

```
>> syms a
y = (a-3)*a^2 + (a-3)*(3/(a-1)) - (a-3)*(2/(a+9));
z = collect(y,a-3)
z =
(3/(a - 1) - 2/(a + 9) + a^2)*(a - 3)
>>
```

First, we created a symbolic variable ‘a’ with the ‘syms’ command. We can use this variable to construct our equation.

Consider that we have a complex equation or polynomial. We defined it in Matlab® as ‘y’. And we want to collect the all equation inside the ‘a-3’ parenthesis.

YOU CAN LEARN MatLab® IN MECHANICAL BASE; Click And Start To Learn MatLab®!

To do it, we used the ‘collect()’ command. We just typed the ‘y’ and ‘a-3’ respectively to define the equation and collecting variable. You can see the result that equation ‘y’ is collected inside the parenthesis of ‘a-3’.

```
>> syms a b
y = (a-3)*b^2 + (a-3)*(3/(b-1)) - (a-3)*(2/(b+9));
z = collect(y)
z =
((a - 3)*b^4 + (8*a - 24)*b^3 + (27 - 9*a)*b^2 + (a - 3)*b + 29*a - 87)/(b^2 + 8*b - 9)
>>
```

In this example, we have an equation that has two variables ‘a’ and ‘b’. To obtain a more homogeneous polynomial, we can use the ‘collect()’ command again. Check the answer above.

As you understand the ‘collect()’ command is a very useful command in Matlab® to collect complex equations and polynomials. You can use this command instead of making hand calculations.

Do not forget to leave your comments and questions below about the use of the ‘collect()’ command in Matlab® below.

If you want further coding examples about the ‘collect()’ command in Matlab®, inform us in the comments.

This article is prepared for completely educative and informative purposes.

There are no comments for this article yet! You can make the first comment.