polyval doesn't recognise input as numeric value

Hello to all,
I want to create a loop where a value x is calculated through interpolation. In the first run "x = polyval(p,y);" works fine. In the end of the first run I get:
x =
48845.957126841025088289460260046
In the second run where x has changed, even though x is a number, polyval gives me an error saying "Error using filter Invalid data type. Input arrays must be numeric or logical.". Putting the value manually doesn't give the error.
Has anyone faced this error before?
Best regards,
Paris Pasqualin

2 Comments

It will work for all the cases if the input is double. You need not to use a loop, you can input x as an array. Show us how was x which threw error.
I'm afraid I explained myself really badly, please let me reformulate.
I use vpasolve() to solve a set of equations which represents my system. Some parameters, which appear in the set of equations, depend on the value x which is one of the inputs in my system.
s = polyval(p_s,x);
p = polyval(p_s,x);
y is the output of the system. In the second run I want x = y to simulate a multistage system. “x = y” gives a value in the form of:
x =
48845.957126841025088289460260046
On the second run when I calculate s and p, I get the error saying:
" Error using filter
Invalid data type. Input arrays must be numeric or logical.
Error in polyval (line 56)
y = filter(1,[1 -x],p); "
I hope this explanation is clearer. Thanks so much for the response.

Sign in to comment.

 Accepted Answer

the length of the output tells us that x is symbolic not double precision. polyval cannot work on symbolic.
(polyval is easy to code for symbolic use if you have not used centering and scaling)

4 Comments

Then why does she say "In the second run where x has changed" when he put a different y into polyval()? If "polyval cannot work on symbolic" y, then she should not have gotten an x output at all, much less a changed one. Why would polyval() return a double x for one y input, and return a symbolic x for a different y input? If she did in fact get a symbolic x out, then maybe she put a symbolic y in? I don't know -- I don't have the symbolic toolbox. Not sure if she does either since she didn't list it when he posted (maybe that was an oversight).
I don't know what symbolic and doubleprecision mean.
I made an error while writing my question, these is a clearer version:
I use vpasolve() to solve a set of equations which represents my system. Some parameters, which appear in the set of equations, depend on the value x which is one of the inputs in my system.
s = polyval(p_s,x);
p = polyval(p_s,x);
y is the output of the system. In the second run I want x = y to simulate a multistage system. “x = y” gives a value in the form of:
x =
48845.957126841025088289460260046
On the second run when I calculate s and p, I get the error saying:
" Error using filter
Invalid data type. Input arrays must be numeric or logical.
Error in polyval (line 56)
y = filter(1,[1 -x],p); "
Thank you both for your responses.
If you used vpasolve, then you used a symbolic toobox tool. The result will not be a double or single precision number, but a floating point SYMBOLIC number. polyval CANNOT use that value. Polyval works ONLY on singles or doubles. Just because something looks like a number does not make it a number as it is stored in MATLAB. For example, the string '1.2345' may look like a number, but that does not make it a number, then usable by polyval.
You can convert the output of vpa/vpasolve to a double using double.
Thanks so much for the explanation, very much appreciated

Sign in to comment.

More Answers (0)

Categories

Find more on Functions in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!