How can I fit experimental data to a system of implicit equations (using optimization toolbox?)

I constructed the following code to fit experimental data to one implicit equation using optimization toolbox.
y = (A3*(x/(x+A1))*exp(B1*(B2-B3+A4-y*V*A2)))
Here
  • x is the independent variable
  • y is the dependent variable.
  • B1, B2 and B3 as well as V are known constants
  • A1, A2, A3, and A4 are unknown parameters that I want to use the code to find.
The code I used is the following:
% define experimental data
x = ...
[240;220;195;170;145;120;95;75;50;35;25;12.5;6;0]*1e-6;
y = ...
[-1;-0.95;-0.94;-0.90;-0.87;-0.84;-0.77;-0.67;-0.56;-0.48;-0.37;-0.20;-0.13;0];
x = x';
y = y';
% define initial guess for A1-A4, and upper limit (ub) and lower limit (lb)
Fit_Params = [100e-6 200 10 0.1]; %insert initial guess here
lb = [0 0 0 0];
ub = [1e-3 300 1000 0.8];
% Plot y = f(x) using initial guess parameters
ezplot(@(x)myImplicitF(x,Fit_Params),[0e-6 250e-6]) %plot y = f(x)
% Find best fit value for parameters using lsqcurvefit
lsqcurvefit(@(params, xdata) myImplicitF(xdata,params),Fit_Params, x, y, lb, ub)
% Define implict function y = f(y,x)
% numerically computes the value of y by calling the FSOLVE function.
function yout = myImplicitF(x, Parameters)
B1= -40;
B2 = 0.1;
B3 = 0.5;
V = 20e-4;
A1=Parameters(1);
A2=Parameters(2);
A3=Parameters(3);
A4=Parameters(4);
yout = zeros(size(x));
opt = optimset('display','off');
for i=1:length(x)
yout(i) = fsolve(@(y) y+(A3*(x(i)/(x(i)+A1))*exp(B1*(B2-B3+A4-y*V*A2))), 1e-15, opt);
end
end
Question:
In the end, this gives a best fit for parameters for A1, A2, A3, and A4.
The challenge for me is to fit a system of equations. I have multiple datasets for variable y for different values of reaction volume (V = [20, 40, 60, 80]), while the independet variable x remains the same.
x = [240;220;195;170;145;120;95;75;50;35;25;12.5;6;0]*1e-6;
y1 = [-1;-0.95;-0.94;-0.90;-0.87;-0.84;-0.77;-0.67;-0.56;-0.48;-0.37;-0.20;-0.13;0]; %for v = 20.
y2 = [another array]; %for v = 40,
y3 = [another array]; %for v = 60,
y4 = [another array]; %for v = 80,
I want to find the best fit for A1, A2, A3 and A4 to minimze the sum of square error for all four equations at once, instead of the code I showed which fits to one equation at a time. Any suggestions on how to do this?
Thanks in advance

Answers (0)

Categories

Products

Release

R2020a

Asked:

on 4 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!