Fitting a nonlinear curve to a small dataset
Show older comments
My data is
Data = ...
[2.5 -14.741408
3.0 -14.765364
4.0 -15.854609
5.0 -16.058246
6.0 -16.103032
7.0 -16.595257];
and looks like this

I want to fit a single curve to this and get the equation of that curve. How may I do this?
Accepted Answer
More Answers (1)
esat gulhan
on 15 Sep 2020
x=[2.5 3.0 4.0 5.0 6.0 7.0];
y=[-14.741408 -14.765364 -15.854609 -16.058246 -16.103032 -16.595257];
s=pchip(x,y) %you can use pchip or cape instead of pchip
xx=linspace(2.5,7,100);yy=ppval(s,xx)
plot(xx,yy,'LineWidth',1.5);grid on;hold on;plot(x,y,'o')
ppval(s,3) %if you want to know y when x 3 this code works, if you want y when x 5 you should enter 5
ppval(s,5) %if you want y when x 5 you should enter 5 like that
3 Comments
Imran
on 15 Sep 2020
esat gulhan
on 15 Sep 2020
You can get a function from Cfit data tool
a0 = -15.79
a1 = -0.6927
b1 = 0.07262
a2 = 0.2647
b2 = -0.3676
w = 1.016
y= a0 + a1*cos(x*w) + b1*sin(x*w) + a2*cos(2*x*w) + b2*sin(2*x*w)
You can get a fourier function like that. Pchip is better to use
esat gulhan
on 15 Sep 2020
if it works please accept the answer.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



