Fit model with 3 independent variables and many parameters to data?

Is it possible to use the fit() function to fit a model with 3 independent variables and many parameters (coefficients)? Reading through the documentation, I get the impression that Matlab only supports 2 independent variables. Any insight would be helpful.
Thanks, Justin

1 Commento

For more general kinds of fitting, you probably need Optimization Toolbox solvers.

Accedi per commentare.

 Risposta accettata

Do you have the Statistics or Optimization Toolboxes? If so:
Optim:
* doc lsqcurvefit
* doc lsqlin
* doc lsqnonlin
Stats:
* doc NonlinearModel
* doc LinearModel
* doc regress
I'm missing many others, we can point you in a more specific direction if you have more details.

4 Commenti

I do have those toolboxes so I think this gets me going in the right direction. Thanks! If you're curious, this is a really tricky fitting problem. I have a model that is a function of 3 independent variables (r, th, phi):
c=C*(1-(r/R(th,phi))^2)^n + cmin
Thus the parameters (or coefficients) I need to find are C, n, cmin, and R. The tricky part is that R is actually a function of th, and phi. This function is only numerically defined, i.e., I only need to know what R is at certain discrete values of th and phi. Therefore, I've been thinking of R as an array of parameters that I need to find. So if R is an m x n array, the total number of parameters I need to find is 3 + (m x n). In general, m and n will probably be somewhere between 5 and 20. This means that its possible that I have to do this fit with 3 independent variables and up to 403 parameters. Now that I've written this down, it seems kind of unreasonable. Any thoughts?
Sorry, didn't read the last part about 403 parameters. That makes it sound less feasible. Can you post what you have.
Sorry, my code is a little bit messy right now (its written in a GUI and it would take me a while to put it in an understandable format).
I've implemented the lscurvefit() routine. It works in a reasonable amount of time if I give it a good starting guess and limits.
Anyways, is there a way to weight input data points (ydata)? In other words, some of my data points are less important than others so I would like to minimize a 'weighted' sum of square errors instead of the normal sum of square errors used by default. Possible? Thanks again for your help.
I just saw that I can use lsqnonlin() instead of lsqcurvefit() to do what I need because in lsqnonlin() the function that your minimizing is supposed to return the residuals instead of the predicted values as in lsqcurvefit(). Thus I can just weight the residuals that are returned in my function definition.

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by