Curve fitting to data sets with multiple parameters
27 次查看(过去 30 天)
显示 更早的评论
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.
Adam
0 个评论
回答(3 个)
Richard Willey
2011-6-2
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)
0 个评论
Andrew Newell
2011-6-2
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).
2 个评论
Andrew Newell
2011-6-2
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!