MATLAB: How can we fit hyperbola to data

curve fittinghyperbola

Hi, I have x and y coordinates for my data points. The data is fitted well with exponential fitting. However, I have to fit a hyperbola (a must condition for my results). I am using code,
% fit data k=0.002; % hit and trial
x = 1/xdata; y = k*1/x; p=plot(x,y)
I have attached excel file of my data. Accept my thanks in advance.

Best Answer

Try this:
D = xlsread('data for hyperbola fitting.csv');
D = sortrows(D,1);
x = D(:,1);
y = D(:,2);
hyprb = @(b,x) b(1) + b(2)./(x + b(3)); % Generalised Hyperbola
NRCF = @(b) norm(y - hyprb(b,x)); % Residual Norm Cost Function
B0 = [1; 1; 1];
B = fminsearch(NRCF, B0); % Estimate Parameters
figure(1)
plot(x, y, 'pg')
hold on
plot(x, hyprb(B,x), '-r')
hold off
grid
text(0.7, 0.52, sprintf('y = %.4f %+.4f/(x %+.4f)', B))
‘Accept my thanks in advance.’
The sincerest expression of appreciation here on MATLAB Answers is to Accept the Answer that most closely solves your problem.