MATLAB: Multi-dimensional Fitting

custom equation solverfittingMATLABmulti-dimensional

I have 3 parameters for my function. Let's say f(x,y,z)=(a*x+b)*exp(-y/c)*(z^2+d) (Or i have n parameters).
I constructed the custom function because I know the behavior of the function (that I desire).
I have many samples(around 5000). For example f(1000,10,2)= 35;
Is there a method to fit these samples into a shape,solid (for 3 parameters case) ?
Or is there a method that to find the coefficients (a,b,c,d in this case) for my custom function using all my samples?
The answer doesnt have to be a specific for 3 parameter case, i need actually a solution for n parameters case.
(I know Matlab has curve fitting and surface fitting tools but no more dimensions.)
Any support will help me, thanks.

Best Answer

You cannot use cftool it supports at most two independent variables and on dependent variable. You can, however, use your custom equation with fit() from the Curve Fitting Toolbox, or you could use nonlinear least squares https://www.mathworks.com/help/optim/nonlinear-least-squares-curve-fitting.html
fit() is often surprisingly efficient at what it does, and often generates coefficients that are close enough to optimal to be "good enough" for practical purposes.
However, in equations that have two or more major basins of attraction, fit() will typically go with the larger basin even when the smaller basin has a significantly better fit. Adding upper and lower bounds on the "reasonable" values of parameters can help a lot.
I would predict that the in your sample equation, the c value would tend to vary a lot. You do not have have an additive constant so the fitter would tend try to raise or lower the overall height by driving c large, but large values of c lead to small -y/c leading to near 1 value of exp() and relatively large changes in c have small effects, making it difficult to locate the best c value. This is a common problem for equations with exp() and a multiplicative coefficient inside.
Related Question