Quadratic/Exponential Best Fit Curve
72 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hamish Brown
el 16 de Nov. de 2021
Respondida: John D'Errico
el 16 de Nov. de 2021
i'd like to add a quadratic or exponential best fit curve to my scatter graph. I cant figure out how to do it. I've tried the following but it doesn't give the type of curve i'd like. I also have the curve-fitting package installed.
y = [0.1 0.2 0.3 1.3];
x = [180 598 2259 8853];
plot(x,y,'x')
p = polyfit(x,y,7)
f = polyval(p,x)
hold on
plot(x,f,'--r')
hold off
0 comentarios
Respuesta aceptada
John D'Errico
el 16 de Nov. de 2021
First, you have 4 data points. Trying to fit a degree 7 (SEVEN) polynomial to that is just silly. Yes, you say quadratic. But your words don't fit what you did.
Putting multiple fits on one plot is easy though.
y = [0.1 0.2 0.3 1.3];
x = [180 598 2259 8853];
plot(x,y,'x')
Lets be completely serious. You want to use those 4 data points to try to fit anything? These 4 points do not have the shape of a quadratic polynomial. They lack the shape of an exponential function. And that means what you get out will be complete garbage for a model.
You could arguably get just as valid a fit from a straight line through the data.
mdlpoly1 = fit(x',y','poly1');
mdlpoly2 = fit(x',y','poly2');
You don't say WHICH exponential model you want to use. And with only 4 data points, hoping to do any such fit is problematic for an exponential model.
expft = fittype('a*exp(b*x)','indep','x');
mdlexp = fit(x',y',expft,'start',[1 0.0001])
Anyway, now we can plot the results.
plot(mdlpoly1,'m')
hold on
plot(mdlpoly2,'b')
plot(mdlexp,'g')
plot(x,y,'ro')
I have little confidence about which of those curves fits the data better. They are jerked around by the influence of the first and third data points, but which of those two points is noisy? Or is it the second point that is garbage?
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!