Using Solve function for polynomial

2 views (last 30 days)
Hi there I want to solve an equation below but i faced a problem.
i tried to solve this with following code but it did not works:
i already have Fc and m , i tried to find nc Please Help

Accepted Answer

John D'Errico
John D'Errico on 1 Aug 2016
Edited: John D'Errico on 1 Aug 2016
You cannot use solve to solve this because in general there is no exact solution. (And polynomials are still not involved.)
I suppose, if you want to use the extension of factorial into the real line using the special function gamma:
factorial(x) = gamma(x+1)
then you can write it as:
Fc - gamma(m+1)/(gamma(nc+1)*gamma(m-nc+1)) + nc == 0
but even here there will be no analytical solution.
syms nc
m = 5;
Fc = 8;
solve(Fc - gamma(m+1)/(gamma(nc+1)*gamma(m-nc+1))+nc,nc)
Warning: Cannot solve symbolically. Returning a numeric approximation instead.
> In solve (line 303)
ans =
2.7090797227280332212966072765956
I could have used fzero too there. Although there are many values of m for which fzero might fail due to numerical problems. Factorials get really large, really fast. But fzero will work here, using gamma:
fzero(@(nc) Fc - gamma(m+1)/(gamma(nc+1)*gamma(m-nc+1)) + nc,3)
ans =
2.70907972272803
>> fzero(@(nc) Fc - gamma(m+1)/(gamma(nc+1)*gamma(m-nc+1)) + nc,1.5)
ans =
2
It turns out, there are multiple solutions to your problem.
  1 Comment
John D'Errico
John D'Errico on 1 Aug 2016
Edited: John D'Errico on 1 Aug 2016
Sorry, I originally misread your question. I've now fixed my response.
But no. There are at least TWO solutions to the problem.
ezplot(@(nc) Fc - gamma(m+1)./(gamma(nc+1).*gamma(m-nc+1)) + nc)
grid on
2 is one solution. But 2.709... is the second solution, as you can see from the plot.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 1 Aug 2016
syms nc
solve(Fc == factorial(m) / (factorial(nc)*factorial(m-nc)) - nc)
  1 Comment
Alireza Lashgary
Alireza Lashgary on 1 Aug 2016
thanks for your reply , but it did not work.
but it has a solution. Fc is 8 , m is 5 and nc must be 2 but i got that warning.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!