Can matlab solve this simple factorial equation?
3 views (last 30 days)
Show older comments
I am interested in knowing whether MATLAB can solve the equation x! == y! to get x == y. I have tried
syms x1 x2
eqns = [factorial(x2) == factorial(x1)];
S = solve(eqns, [x1 x2]);
S.x1
S.x2
But the response is
“Warning: Unable to solve symbolically.
Returning a numeric approximation instead”.
In solve (line 304)
ans =
0
ans =
0
I used the gamma function instead of factorial but get the same response. Any suggestions?
1 Comment
Steven Lord
on 4 Nov 2017
Your proposed solution is incomplete. (x = 0, y = 1) and (x = 1, y = 0) are also solutions.
Answers (2)
John D'Errico
on 3 Nov 2017
Edited: John D'Errico
on 3 Nov 2017
Um, the problem is, this is arguably more complicated than you think.
First of all, lets extend the problem to the real line. We know that
factorial(x) = gamma(x+1)
The gamma function is defined for all values of x, whereas factorial is classically defined for only non-negative integers. You need to do this extension if you will use solve. Solve is not really designed to solve problems with integer variables (thus essentially Diophantine equations.)
If you want to solve that relationship, is it true that x1 == x2? ALWAYS? Yes, it is true that is one solution. But in fact, there are infinitely many solutions to the relationship
gamma(x1+1) == gamma(x2+1)
such that x1 is NOT equal to x2. You can easily convince your self of that fact simply by a plot.
ezplot(@(x) gamma(x+1))
grid on
For example, I'll pick a value of x1.
x1 = 0.2;
gamma(x1+1)
ans =
0.91817
x2 = fzero(@(x) gamma(x + 1) - gamma(x1 +1),2)
x2 =
0.74604
gamma(x2+1)
ans =
0.91817
As you can see, I chose one value for x1, then I found a second value x2, where x1 was not equal to x1, but the two produce the same value.
So there are infinitely many solutions with x1~=x2, if you use the extension of factorial to the real line. vpasolve can give some of them to us, but not solve.
x1 = 0.2;
syms x
x2 = vpasolve(gamma(x1 + 1) == gamma(x+1),x,3)
x2 =
0.74604419294554377739652086343099
x2 = vpasolve(gamma(x1 + 1) == gamma(x+1),x,0)
x2 =
0.19999999999999984718524773398979
x2 = vpasolve(gamma(x1 + 1) == gamma(x+1),x,-2.3)
x2 =
-4.1549616274283604766122794976542
Lets look at it another way. There is no analytical inverse to the gamma function. So a symbolic engine won't understand that it can just take an "inverse" of the gamma function here, getting x1==x2. Symbolic tools don't look at your problem from a high level.
6 Comments
Walter Roberson
on 4 Nov 2017
One thing to keep in mind with the version that returns a pair of 1's is that you are asking to solve a single equation for two variables: normally no result would be expected from that.
Torsten
on 3 Nov 2017
syms x1 x2
eqn = factorial(x2) == factorial(x1);
S = solve(eqn, x1)
Best wishes
Torsten.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!