MATLAB: Determining coefficients of an equation using your experimental data

solving equations

Hello every one. I have an equation with four coefficients. It looks like:
Y= X (a + (b*(Z)^c) * (F^d))
Now I have the values of Y,X,Z, and F from my experiments. How can use these values to determine the values of these coefficients in matlab? Thanks

Best Answer

What you refer to as ‘coefficients’ are actually called ‘parameters’. Estimating them is relatively straightforward. I am using fminsearch here, but the function ‘Yfit’ will work with the Statistics Toolbox nlinfit and the Optimization Toolbox lsqcurvefit functions. See the relevant documentation for details.
% Original Equation: Y = X * (a + (b*(Z)^c) * (F^d))
% Variable Matrix:
Y = Y(:);
XZF = [X(:) Z(:) F(:)];
% Parameters: a = b(1), b = b(2), c = b(3), d = b(4)
Yfcn = @(b,XZF) XZF(:,1) .* (b(1) + (b(2).*(XZF(:,2).^b(3)) .* XZF(:,3).^b(4)));
SSECF = @(b) sum((Y - Yfcn(b,XZF)).^2);
B0 = rand(4,1)*100; % Initial Parameter Estimates
[B,SSE] = fminsearch(SSECF, B0);
The ‘XZF’ matrix is necessary because most functions take only two parameters, the parameter vector and the independent variable. The ‘SSECF’ function is the sum-squared-error cost function for a least-squares fit. The estimated parameters are in the ‘B’ vector, and ‘SSE’ is the sum-squared-error when fminsearch ends.
This code works with created data, but fitting the parameters may be very difficult. It is important for your function here that your initial parameter estimates are as close to their actual values as you can estimate them to be. I cannot guarantee that fitting your function will give you the most appropriate parameters, in terms of their physical validity. You may have to experiment with several — perhaps hundreds — of different initial parameter estimates before you get a set that converges on physically appropriate estimates.
Because your data are actually 4-dimensional (with ‘Y’, ‘X’, ‘Z’, and ‘F’), you will not be able to plot it, or plot the fitted curve to it.