Least square fitting of data
1 view (last 30 days)
Show older comments
Abhay Athaley
on 31 Jan 2018
Commented: Star Strider
on 31 Jan 2018
Hi,
I have data(xdata,ydata) and want to fit a model with the data. The model is a generic one y=k/x, k is constant according to the shape of the data points. My questions are: 1. How can I know the precise form of the model? 2. After using lsqcurvefit, I get the constant. How can I get the equation itself to predict new y from new x.
Here is my data: xdata:[2;10;20;30;40;50;60;70;80;90;99.598] ydata: [98913.08;19922.26;10046.06;6751.64;5107.10;4116.99;3457.18;2988.11;2637.81;2358.34;2147.66]
Thanks in advance
0 Comments
Accepted Answer
Star Strider
on 31 Jan 2018
Do this:
xdata = [2;10;20;30;40;50;60;70;80;90;99.598];
ydata = [98913.08;19922.26;10046.06;6751.64;5107.10;4116.99;3457.18;2988.11;2637.81;2358.34;2147.66];
eqn = @(k,x) k./x; % Define Objective Function
B = lsqcurvefit(eqn, 1, xdata, ydata); % Estimate Parameter
xv = linspace(min(xdata), max(xdata)); % Create New ‘x’ Vector
yv = eqn(B,xv); % Use ‘B’ And ‘xv’ In ‘eqn’ TO Calculate ‘yv’
figure
plot(xdata, ydata, 'pg')
hold on
plot(xv, yv, '-r')
hold off
grid
2 Comments
More Answers (0)
See Also
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!