I am having trouble with some basic plotting using the polyval function.
5 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Guillaume
on 8 Oct 2017
Edited: Guillaume
on 8 Oct 2017
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.
0 Comments
See Also
Categories
Find more on Polynomials 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!