Function with 4 independent variables and 3 parameters

7 views (last 30 days)
I need help on my research project. I have an equation which relates different data (in 5 columns, one column per one data type, each column has 22 data points), 4 independent and 1 dependent variables. This equation also has 3 fit parameters. I need to find those 3 fit parameters and also minimize the objective function which is the sum of deviations between computed and experimental results (which is the dependent variable before fitting).
Please, instruct me which options are available in Matlab or in Excel solver. I need guidance in doing this, since I am not experienced in this topic in Matlab nor in Excel solver.
Thanks, Di

Answers (1)

Walter Roberson
Walter Roberson on 21 Oct 2020
You can also use the Curve Fitting toolbox with a custom equation; https://www.mathworks.com/help/curvefit/custom-nonlinear-models.html
The first of those links includes an example of finding the sum of squares of the residues and using fminunc() . I find it to be more effective to use fminsearch() for these purposes -- I find that fminunc gets stuck in local minima too easily.
  2 Comments
Di Kha
Di Kha on 15 Nov 2020
Sory for my late reply, had emergency cituation. Thank you for those two links. I read them and realized that examples and options given are for the functions (y) with either one or two variables being (x) or (x,z). If it is one variable function with multiple fit parameters it gives a 2D graph, for a function with 2 variables and multiple fit parameters it gives a surface. I do not think that my case mathces any of those 2 possibilities. I do have a function (y) which depends on let say (x), (z), (t), and (k). Ans this (y) function has 3 fit parameters namely (m1), (m2), and (m3).
Then i need to minimize the objective function which is the sum of deviations between computed (includes fit parameters) and experimental results.
Any further recomendation?
Di
Walter Roberson
Walter Roberson on 15 Nov 2020
Edited: Walter Roberson on 15 Nov 2020
rng(655321)
x = sort(randi(100,22,1));
z = rand(size(x)) + rand(size(x)).^2 - rand(size(x));
t = exp(-randn(size(x)).^2);
k = log(x)/2 + exp(z) - t + rand(size(x));
y = sort(rand(size(x)));
model = @(a,b,c) a*cos(pi*x/100) + b*z + gamma(t)./gamma(k) + c;
residue = @(abc) sum((model(abc(1),abc(2),abc(3)) - y).^2);
abc0 = [1 2 -3];
[abc, fval] = fminsearch(residue, abc0);
disp(abc)
1.1766 1.5062 -2.5047
disp(fval);
693.4345
The data here and model is completely made up just to have something to show you how it worked.
The results obtained have a, b, c within 1e-5 of the best locations I can find using other techniques.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!