How can I fit a smooth curve to this data and get the equation of the curve?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gucci
am 4 Apr. 2022
Kommentiert: Alex Sha
am 5 Apr. 2022
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');
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 4 Apr. 2022
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')
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 Kommentare
Voss
am 5 Apr. 2022
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
am 5 Apr. 2022
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/952774/image.jpeg)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!