Nonlinear regression with two variables
显示 更早的评论
Hello all, I want to fit a nonlinear model to a set of experimental data. It has 1 dependent variable, Y, and 2 indepenent variables, X1 and X2.
I have this equation. Y = C * ((X1)^1/2 * (X2)^a. I'd like to determine the values of the parameters, C and a.
X1 = QG_Lmin.*1.67*10^-5;
X2 = QG_Lmin ./ QL;
% Define the model function
model = @(coefficients, x) coefficients(1) * sqrt(x(:, 1)) .* x(:, 2).^coefficients(2);
% Define the initial parameter values
initialCoefficients = [1, 1];
% Perform nonlinear regression using lsqcurvefit
estimatedCoefficients = lsqcurvefit(model, initialCoefficients, [X1, X2], Y);
% Extract C and a from the estimated coefficients
C = estimatedCoefficients(1);
a = estimatedCoefficients(2);
But I got an error:
Initial point is a local minimum.
Optimization completed because the size of the gradient at the initial point
is less than the value of the optimality tolerance.
<stopping criteria details>
Could anyone help me out?
回答(1 个)
I don't know your inputs, but theoretically, it works:
X = rand(50,2);
Y = rand(50,1);
% Define the model function
model = @(coefficients, x) coefficients(1) * sqrt(x(:, 1)) .* x(:, 2).^coefficients(2);
% Define the initial parameter values
initialCoefficients = [1, 1];
% Perform nonlinear regression using lsqcurvefit
estimatedCoefficients = lsqcurvefit(model, initialCoefficients, X, Y);
% Extract C and a from the estimated coefficients
C = estimatedCoefficients(1)
a = estimatedCoefficients(2)
Maybe your arrays X1 and X2 contain NaN or Inf values.
类别
在 帮助中心 和 File Exchange 中查找有关 Support Vector Machine Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!