Hello 浩天,
I will be answering your query in English, since I am not proficient in Chinese. Based on your description, it seems you want to minimize the error between the theoretical value and the experiment value based on the equation containing an independent variable.
A common approach for such error minimization is to leverage the MATLAB’s Optimization Toolbox by the method of non-linear squares fitting. Here is the detailed overview of the possible steps:
1. The format or data type of the independent variable (x) and the experimentally measured (y2) must be same, typically vectors. Here is an example code for your reference:
x_data = [x1, x2, x3, ..., x100]; % Your x data
y2_data = [y21, y22, y23, ..., y2100]; % Your y2 data (experimental)
2. Next, you would need to define the equation mentioned in the above problem into MATLAB. This can be done with anonymous function in MATLAB as shown below:
modelFcn = @(p, x) (p(1)*x.^2 + p(2)*x + p(3)) ./ (p(4)*x + p(5));
% p is a vector of the parameters [a,b,c,d,e] of your equation
To learn more about anonymous functions, kindly refer to the link below:
3. For the defined parameters of the equation, you can make an initial guess which might help in the convergence of the optimization algorithm.
initialGuess = [1, 1, 1, 1, 1]; % Example guess
4. Now, you can utilize the “lsqcurvefit” to fit your equation to the data to minimize the sum of squares of the deviations i.e. errors. You can refer to the below code to know how to use the function in the context of your problem:
% Define options for lsqcurvefit (optional)
options = optimoptions('lsqcurvefit','Display','iter','Algorithm','trust-region-reflective');
% Perform the fitting
[p_est,~,residual,exitflag,output] = lsqcurvefit(modelFcn, initialGuess, x_data, y2_data, [], [], options);
% p_est will contain your fitted parameters [a, b, c, d, e]
To learn more about "lsqcurvefit" function, kindly refer to the link below: