Polyval/Polyfit input values
显示 更早的评论
Hi, I'm new to MatLab and I've been attempting to use Polyval/Polyfit.
The code resembles something like this:
xmin=5;
xmax=100;
xrange = xmin:xmax;
p = [6 2 4 1 1];
polyval(p, xrange)
For some reason, the above results in a list of return values that are not in numerical order. In other words, the y values calculated using polyval are not all in the order that they should be in. Sporadically there are negative values outputted in the return between positive values.
For the function y=6x^4 + 2x^3 + 4x^2 + x + 1 where all my input values are positive, this theoretically should not be the case.
It is also interesting to note that if I instead insert xmin and xmax directly into the polyval parameters, the return values are in correct order.
Anyone ever run into a similar problem?
Thanks!
1 个评论
Are Mjaavatten
2016-4-23
When I enter your code into Matlab I get nice positive values that increase monotonically, as expected. Could it be that you have accidentally redefined polyval? Try
which polyval
This should result in something like
C:\Program Files\MATLAB\R2014b\toolbox\matlab\polyfun\polyval.m
If you get a very different answer, enter the command
clear polyval
to revert to the original behaviour.
采纳的回答
更多回答(1 个)
Image Analyst
2016-4-23
编辑:Image Analyst
2016-4-23
This works fine:
xmin=5;
xmax=100;
xrange = xmin:xmax;
p = [6 2 4 1 1];
y=polyval(p, xrange)
plot(xrange, y, 'b*-')
grid on;
No negatives, and nothing out of order. Demos attached.
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!