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

5 ビュー (過去 30 日間)
Grant Piephoff
Grant Piephoff 2017 年 10 月 8 日
編集済み: Guillaume 2017 年 10 月 8 日
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 Center および File ExchangePolynomials についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by