Operator '==' is not supported for operands of type 'function_handle'

1 visualización (últimos 30 días)
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!

Respuesta aceptada

JacobsonRadical
JacobsonRadical el 24 de Abr. de 2022
Ok I figured it out. My code had mistakes. To declare the variable x, I should use
syms x
However, my original code used
sym x
Hence, with all the things unchanged, to solve it (I use numercially solve here), the following code suffices:
syms x
eqn = polyproduct(x) == 0
vpasolve(eqn,x)
This indeed gave me the solution.
  4 comentarios
JacobsonRadical
JacobsonRadical el 11 de Mayo de 2022
Editada: JacobsonRadical el 11 de Mayo de 2022
I am that user. But I have been out of the field of probablity theory/stochastic analysis for a long time. I only studied it when I took a course for my master degree (well its a PhD course for PhD student, so I might not understand all of them, like those PhD students). I think that the problem here is the interpretation and definition of a stochastic process.
"In that sense, it is not possible to say "there are no decreasing sample paths" but rather that the probability of a sample path being in the set of decreasing functions is zero. "
I don't think that you are wrong. There is a way to define Possion process to require no decreasing sample path almost surely, which is exactly what you mean. Just like defining Wiener process (or Browninan motion), you can require the definition to be strict, or to be ture almost surely. It really depends on convention. And in this case, if I directly require that there are no decreasing sample path, then it covers your almost surely definition.
To your confusion about the definition of a stochastic process, here is what I used.
This does not say anything about the continuity, which is defined by using "trajectory".
So by saying a stochastic process being continuous, at least I am referring to the trajectory (the path) is continuous in the time t, for each fixed omega.
I am not sure if this answers your question.
JacobsonRadical
JacobsonRadical el 11 de Mayo de 2022
Editada: JacobsonRadical el 11 de Mayo de 2022
I never consider a stochastic process as a measure. It is a collection measurable functions "indexed" by the time t. This definition indeed has problem of the existence of a stochastic process, because you can for sure require some family of random variables to satisfy anything you want but then there may not exist a probability distribution for this process. To thie end, you need to check by checking the consistency of all the family of finite distribution of this process and using the Daniell-Kolmogorov Consistency Theorem.
I am not sure what definition you are using. But you view any process as a measure, which is a better way --- by specifying the measure/distribution, you are sure that you have such a process.
I pointed out in that MSE post that, the definition you are referring to, is not the one I prefer, because you never know such a process could ever exist, and simply defining a process by giving some properties that one likes to have should not be the correct way to do so --- one must specifcy the measure/the distribution (as what I wrote in the definition I preferred) --- or one needs to prove that such a process exists.
One should always firstly have a distribution and then to have a concrete description of the process.
I am again not sure if this is why you are confusing.

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 24 de Abr. de 2022
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 comentarios
John D'Errico
John D'Errico el 24 de Abr. de 2022
Editada: John D'Errico el 24 de Abr. de 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
JacobsonRadical el 24 de Abr. de 2022
I am not really an expert of the computer arithmetic. The point for me is to have numercial solution. So the first idea for me is to simply numerically solve the product I defined. It has an advantage for me, in the way that the solution is given from the lowest value to the highest value. Then, I don't need to sort.
To use the "roots" command, I need to compute the roots of each polynomial, and then I need to put them into one set and I sort them. I am not sure if this is more complicated than what I originally wanted. And as I have figured out, the product can be numercially solved.
"You will never be able to do anything meaningful with the product polynomial in double precisoin arithmetic." I believe that there must be something of computaional science going on behind your recommendation, and I am sorry for not knowing these notions.

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by