how to do curve fiting of polynom?

1 回表示 (過去 30 日間)
elina sk
elina sk 2019 年 1 月 3 日
編集済み: Star Strider 2019 年 1 月 3 日
q_vec=-0.0141600000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.00943999999999996 -0.00944000000000003 -0.00944000000000003 -0.00707999999999998 -0.00707999999999998 -0.00472000000000001
s_veq=0.700000000000000 0.909545454545454 1.11909090909091 1.32863636363636 1.53818181818182 1.74772727272727 1.95727272727273 2.16681818181818 2.37636363636364 2.58590909090909 2.79545454545455 3.00500000000000
plot(s_veq,q_vec)
  1 件のコメント
Luna
Luna 2019 年 1 月 3 日
Hi Elina,
Please first explain your question clearly and what do you want to do.
Also please correct your syntax error on that code part you have shared.

サインインしてコメントする。

回答 (2 件)

Star Strider
Star Strider 2019 年 1 月 3 日
編集済み: Star Strider 2019 年 1 月 3 日
Try this:
q_vec = [-0.0141600000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.00943999999999996 -0.00944000000000003 -0.00944000000000003 -0.00707999999999998 -0.00707999999999998 -0.00472000000000001];
s_veq = [0.700000000000000 0.909545454545454 1.11909090909091 1.32863636363636 1.53818181818182 1.74772727272727 1.95727272727273 2.16681818181818 2.37636363636364 2.58590909090909 2.79545454545455 3.00500000000000];
plot(s_veq,q_vec)
How are ‘S’ and ‘Q’ related to ‘s_veq’ and ‘q_vec’?
EDIT —
With respect to fitting them, it depends on what you want to do.
Two examples:
q_vec = [-0.0141600000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.00943999999999996 -0.00944000000000003 -0.00944000000000003 -0.00707999999999998 -0.00707999999999998 -0.00472000000000001];
s_veq = [0.700000000000000 0.909545454545454 1.11909090909091 1.32863636363636 1.53818181818182 1.74772727272727 1.95727272727273 2.16681818181818 2.37636363636364 2.58590909090909 2.79545454545455 3.00500000000000];
p1 = polyfit(s_veq,q_vec,1);
v1 = polyval(p1, s_veq);
p5 = polyfit(s_veq,q_vec,5);
v5 = polyval(p5, s_veq);
figure
plot(s_veq,q_vec, 'pg', 'MarkerFaceColor','g')
hold on
plot(s_veq, v1, '-b')
plot(s_veq, v5, '-r')
hold off
grid
legend('Data', '1^{st}-Order Polynomial', '5^{th}-Order Polynomial', 'Location', 'NW')

Luna
Luna 2019 年 1 月 3 日
As far as I understand from your question I have fixed your array definition as follows:
Please read my comments below. And check this link for more info: Polynomial Curve Fitting
q_vec= [-0.0141600000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.0118000000000000 -0.00943999999999996 -0.00944000000000003 -0.00944000000000003 -0.00707999999999998 -0.00707999999999998 -0.00472000000000001];
s_veq=[0.700000000000000 0.909545454545454 1.11909090909091 1.32863636363636 1.53818181818182 1.74772727272727 1.95727272727273 2.16681818181818 2.37636363636364 2.58590909090909 2.79545454545455 3.00500000000000];
%% Fitting part
p = polyfit(s_veq,q_vec,2); % gets the coeffs of fitted polynomial, I used 2nd degree you can change it by yourself as you wish.
f = polyval(p,s_veq); % creates the new y axis values from that polynomial.
plot(s_veq,q_vec,'*r',s_veq,f,'-b'); % plots red stars the existing data and blue line for fitted data.
% your polynomial coefficients are in the array p with P(X) = P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1) descending order.
% your polynomial results are in the array f which gives Y = P(X).

カテゴリ

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