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

1 vue (au cours des 30 derniers jours)
Grant Piephoff
Grant Piephoff le 8 Oct 2017
Modifié(e) : Guillaume le 8 Oct 2017
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!

Réponses (1)

Guillaume
Guillaume le 8 Oct 2017
Modifié(e) : Guillaume le 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.

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by