You need an optimization algorithm for smooth, R^n -> R
functions. Since you have only access to barebone Matlab, a good idea is to take an algorithm from File Exchange. For illustration I picked LMFnlsq
, which should suffice since you have a small problem, although it seems to be more general and a little bit overkill here.
Download LMFnlsq
and add to your Matlab path.
Example
For convenience make a function called regr_fun
:
function y = regr_fun(par, x)
alpha = par(1);
beta = par(2);
gamma = par(3);
y = (1 - alpha + alpha./sqrt(1 + 2*beta*(gamma*x).^2./alpha)).^(-1) - 1;
end
Curve fitting (in the same folder as regr_fun
):
%---------------------------------------------------------------------
% DUMMY DATA
%---------------------------------------------------------------------
% Generate data from known model contaminated with random noise
rng(333) % for reproducibility
alpha = 2;
beta = 0.1;
gamma = 0.1;
par = [alpha, beta, gamma];
xx = 1:50;
y_true = regr_fun(par, xx);
yy = y_true + normrnd(0,1,1,50);
%---------------------------------------------------------------------
% FIT MODEL
%---------------------------------------------------------------------
% intial point of solver
p0 = [1,1,1];
obj_fun = @(p) sum((regr_fun(p, xx) - yy).^2);
% optimization
p_fit = LMFnlsq(obj_fun, p0);
y_fit = regr_fun(p_fit, xx);
%---------------------------------------------------------------------
% PLOT
%---------------------------------------------------------------------
plot(xx, yy, 'o')
hold on
plot(xx, y_true)
plot(xx, y_fit, '--')
Note
Although matlab.codetools.requiredFilesAndProducts
lists the symbolic toolbox as well, for this problem it is not needed and the function should run withouth that as well.
pinv
could be a good starting point. Use @ and the name of the user to make sure he/she receives a notification, this increases the chances of getting answers. – rozsasarpi