Hi Chris
From what I understand, you would like to fit the nonlinear model with your data set, and you would like to know how to impose the nonlinear equality constraint
In order to achieve data fitting with constraints, I suggest you use the function fmincon (See Documentation) , which allows you to specify nonlinear constraints. You may consider the following steps:
1. Revise the objective function as follows
function diff = fit_simp(x,X,Y)
A=x(1);
B=x(2);
diff = norm(A*log(X+B) + A*log(1+B) - Y);
end
The new function returns a scalar as the data fitting error. You may save the function as a MATLAB file under the same name as the function. See the documentation for the function norm. 2. Create the nonlinear constraint function
function [c,ceq] = nlcon(x, X, Y)
A=x(1);
B=x(2);
c = [];
ceq = A*log(X+B) + A*log(1+B) - Y;
end
This function has two outputs, c is the output of inequality nonlinear constraints and ceq is the output of the equality constraints. Since we only have equality constraints here, I set c=[]. Again, save this function in a MATLAB file.
3. In the main MATLAB script or in the command window, try the following code (Assuming X and Y are column vectors which contain your data set)
>> X0=[1,0];
>> x=fmincon(@(x) fit_simp(x,X,Y),X0,[],[],[],[],[],[],@(x) nlcon(x,0.3,1));
Then, you should have the expected answer. If you would like to have better data fitting accuracy, you can always specify the options (See Documentation) for fmincon. For more information regrading nonlinear constraints, you can refer to the link below:
-Yu
Best Answer