Function with 4 independent variables and 3 parameters
7 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 21 Oct 2020
Some options are described at https://www.mathworks.com/help/optim/ug/nonlinear-data-fitting-example.html
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
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)
disp(fval);
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!