I am having trouble with some basic plotting using the polyval function.

3 次查看(过去 30 天)
Here is my question I am tackling: Fit a second-order polynomial to the data from Table 14.1. In one figure, plot the data and the polynomial curve you obtained. V(m/s): 10 20 30 40 50 60 70 80 F (N): 25 70 380 550 610 1220 830 1450
I thought it would just require a simple polyfit polyval but I must not understand how to do it. Here is my attempt
v = [10 20 30 40 50 60 70 80];
F = [25 70 380 550 610 1220 830 1450];
x=linspace(0,100,0.1);
P=polyfit(v,F,2);
Q=polyval(P,x);
plot(v,F,'b*'), hold on
plot(Q,'r-')
If someone could help me that would be appreciated. Also if you could display what the final 2nd order polynomial is, or at least its coefficients, that would be so helpful!

回答(1 个)

Guillaume
Guillaume 2017-10-8
编辑:Guillaume 2017-10-8
The only issue I see in your script is
x=linspace(0,100,0.1);
which asks for a grand total of 0.1 points between 0 and 100. Matlab rounds that down to 0 points, hence x is empty.
_edit: and the last plot needs x values unless x has a step of 1 and starts at 1.

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by