MATLAB Answers

# Find common factors in two expressions

31 views (last 30 days)
John Miller on 22 Apr 2020
Commented: Ameer Hamza on 5 Jun 2020
Is there some function so I can find a common factor in multiple expressions?
For example: syms x y
a= 5*(x^4/y)
b= 27*(x^4/y)
=> x^4/y is a common factor.
The reason I'm asking this is that I have some very long expressions I need to sum up. In order to shorten some stuff I would like to extract common factors and assign them to some variable. Thankful for any help!
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Ameer Hamza on 22 Apr 2020
Edited: Ameer Hamza on 22 Apr 2020
syms x y
a = 5*(x^4/y);
b = 27*(x^4/y);
common_factor = gcd(a,b);
Result:
>> common_factor
common_factor =
x^4/y
##### 2 CommentsShowHide 1 older comment
Ameer Hamza on 5 Jun 2020
I am glad to be of help!

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!