how to do curve fiting of polynom?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Polynomials 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by