Operator '==' is not supported for operands of type 'function_handle'
Show older comments
I want to find all the non-negative roots of the product of the following polynomials:

So, I did the following:
poly1 = @(x)x;
poly2 = @(x)x-1;
poly3 = @(x)x.^2-3*x+1;
poly4 = @(x)x.^4-7*x.^3+13*x.^2-7*x+1;
poly5 = @(x)x.^8-15*x.^7+83*x.^6-220*x.^5+303*x.^4-220*x.^3+83*x.^2-15*x+1;
poly6 = @(x)x.^3-5*x.^2+6*x-1;
poly7 = @(x)x.^3-6*x.^2+5*x-1;
poly8 = @(x)x.^4-7*x.^3+14*x.^2-8*x+1;
poly9 = @(x)x.^4-8*x.^3+14*x.^2-7*x+1;
polyproduct = @(x)poly1(x).*poly2(x).*poly3(x).*poly4(x).*poly5(x).* ...
poly6(x).*poly7(x).*poly8(x).*poly9(x);
eqn = polyproduct == 0
S = solve(eqn)
I understand that I can directly set up the equation without calling functions, but later I will do something else with those functions --- including plug in specific x, so I want to restore them first. (And I really don't want to restore each one in a seperate file..)
However, Matlab gives the following error:
>> Replication
Operator '==' is not supported for operands of type 'function_handle'.
Error in Replication (line 13)
eqn = polyproduct == 0
If I use the following code instead:
sym x
eqn = polyproduct(x) == 0
S = solve(eqn,x)
Then, it will give the following error:
Unrecognized function or variable 'x'.
Error in Replication (line 14)
eqn = polyproduct(x) == 0
I am not sure what to do instead. I am sorry if this question is dumb... Thank you so much!
Accepted Answer
More Answers (1)
Torsten
on 24 Apr 2022
1 vote
Determine the roots of each polynomial separately using "roots".
The roots of the product will be the union of the roots of the single polynomials.
4 Comments
JacobsonRadical
on 24 Apr 2022
Torsten
on 24 Apr 2022
"sort" sorts the roots.
Why make things more complicated than they are ?
John D'Errico
on 24 Apr 2022
Edited: John D'Errico
on 24 Apr 2022
You DON'T WANT TO SOLVE THE PRODUCT POLYNOMIAL. Doing so creates a massively high order problem when there is no need to do so. And in turn, that means you will have problems resolving the roots. It means you will have numerical problems working wih that very high order polynomial. You will never be able to do anything meaningful with the product polynomial in double precisoin arithmetic.
Since the roots of each individul polynomial are well defined, all you need to do is then sort them. Seriously, that is a problem?
JacobsonRadical
on 24 Apr 2022
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
