# Curve fitting to data sets with multiple parameters

204 views (last 30 days)
I am an engineering student and relatively inexperienced with matlab. I have data sets that describe the relation between a dependent variable of interest and three different independent variables, where the relationship is linear in two of the cases and enxponential in the third. I want to do a fit to define a function that will describe the dependent variable as a function of the three independent variables:
y = f(q,r,s)
How would I go about doing this? Thanks in advance for any help.

Richard Willey on 2 Jun 2011
The easiest way to solve this type of problem is the nlinfit function inside Statistics Toolbox. Here's a simple example that demonstrates how to use nlinfit to solve a similar type of problem.
The only "hard" part that you need to worry about is chosing the right equation that describes the expected relationship between X and Y
% Create an anonymous function that describes the expected relationship
% between X and Y
fun = @(b,X) b(1)*X(:,1) + b(2)*X(:,2) + b(3) * exp(b(4)*X(:,3));
% Create a data set to use for our example
% Specify beta
b = [100; 200; 3; 4]
% Create some X variables
X = rand(100,3);
% Y = fun(X)
Y = fun(b,X) + randn(100,1);
% Specify a vector of starting conditions for the solvers
b0 = [75; 300; 1; 8]
% Perform a nonlinear regression
beta = nlinfit(X,Y, fun, b0)

Andrew Newell on 2 Jun 2011
Clearly the first thing you need to do, if you don't want to get totally frustrated, is spend some time learning MATLAB (see How to learn MATLAB). You need to learn the basics about how to take an exponential, multiply numbers and so on. Then, if you can write out your expression by hand, it should be easy to convert it to MATLAB. Say, for example, your equation is y equals p times q times the exponential of s. The expression would then be
y = p*q*exp(s)
Then you should learn how to create a function (see function, especially the examples at the bottom).

Thanks for you answer. Let me clarify, I'm inexperienced with advanced analysis techniques. I know the basic matlab language and have used the software before. I'm inexperienced when it come to more advanced data analysis, like trying to combine and fit multiple data sets that have one common parameter.
Andrew Newell on 2 Jun 2011
If so, it might help to show us the MATLAB code for the function you want to fit. Also, how exactly do the multiple data sets enter into it? And what is the common parameter? I suggest editing your original question.

Richard Crozier on 2 Jun 2011