How can I fit a smooth curve to this data and get the equation of the curve?

4 次查看(过去 30 天)
I tried lsline but this is for best fit, and doesn't really match this data
How can I fit a smooth curve to this data and get the equation of the curve?
%% current vs power
current = [26, 30, 40, 50, 60, 70, 80];
power = [0.00460174, 0.0475519, 0.214428, 0.441353, 0.712228, 0.91066, 1.05903];
figure;
plot(current,power,'o');

采纳的回答

John D'Errico
John D'Errico 2022-4-4
It is a bad idea to name your variables with the same name as an existing and useful MATLAAB function. Power is one such example.
current = [26, 30, 40, 50, 60, 70, 80];
powr = [0.00460174, 0.0475519, 0.214428, 0.441353, 0.712228, 0.91066, 1.05903];
plot(current,powr,'o')
The problwm is, there are infinitely many functions that will fit that data. Any set of data in fact, can be fit by infintely many possible models. However, here a polynomial is probably adequate. The inflection point in the curve suggests a cubic polynomial would be necessary, so I might try it:
p3 = fit(current',powr','poly3')
p3 =
Linear model Poly3: p3(x) = p1*x^3 + p2*x^2 + p3*x + p4 Coefficients (with 95% confidence bounds): p1 = -8.102e-06 (-1.117e-05, -5.032e-06) p2 = 0.001298 (0.0008073, 0.001788) p3 = -0.04391 (-0.06845, -0.01938) p4 = 0.413 (0.03479, 0.7912)
hold on
plot(p3)
legend('Current vs power data','Cubic fit','location','northwest')
a higher order polynomial would not be justified, but the cubic seems adequate here.
  5 个评论
Voss
Voss 2022-4-5
p3 is the coefficients of the cubic polynomial (see the comment about coefficients in the code I posted), in order of decreasing powers of x, so the equation would be:
p3(1)*x^3 + p3(2)*x^2 + p3(3)*x + p3(4)
polyval evaluates the polynomial at any x you want. I used polyval to get the values to plot in red.
Alex Sha
Alex Sha 2022-4-5
If prefer to another fitting formula rather than the polynomial, one of will be:
y = p1-p2*Exp(-p3*x^p4);
Sum Squared Error (SSE): 0.000194020813066487
Root of Mean Square Error (RMSE): 0.00526471832195211
Correlation Coef. (R): 0.999908440561234
R-Square: 0.999816889505599
Parameter Best Estimate
---------- -------------
p1 1.14840232711552
p2 1.22125975267146
p3 1.50816314630436E-6
p4 3.27583408702712

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by