Fit a curve to a nonlinear 1D data
Mostrar comentarios más antiguos
Hello,
I have a monthly rainfall data for a year and it is quadratic with months. I want to get the approximate equation it follows. I tried Excel and other options and the results are also okay but I was thinking if MATLAB could give a more precise equation for me. After that, I will use that equation for another variable. Below is shown the monthly data. I just want to fit a curve to it and get the equation for my further use. Thank you very much.
18.92, 21.6, 27.4, 43.07, 85.66, 230.12, 347.02, 289.74, 197.32, 95.32, 39.5, 19
Respuestas (1)
Sindar
el 4 de Oct. de 2020
x=1:12;
y=[18.92, 21.6, 27.4, 43.07, 85.66, 230.12, 347.02, 289.74, 197.32, 95.32, 39.5, 19];
% fit to a quadratic (degree 2) polynomial
p = polyfit(x,y,2);
4 comentarios
Abhishek Singh
el 4 de Oct. de 2020
Sindar
el 4 de Oct. de 2020
% half-month steps
x1 = linspace(0,12,25);
% evaluate at these points
y1 = polyval(p,x1);
figure
% plot original data with stars
plot(x,y,'*')
% add fitted data as lines
hold on
plot(x1,y1)
hold off
Abhishek Singh
el 5 de Oct. de 2020
Sindar
el 5 de Oct. de 2020
what do you mean by "lesser co-efficients in p"?
Also, with only 12 data points, I'd be wary of fitting with high-order polynomials (too many parameters, likely to overfit and result in spikes between sampled points)
Categorías
Más información sobre Linear and Nonlinear Regression en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!