Fitting a data set by optimising multiple parameters
8 次查看(过去 30 天)
显示 更早的评论
Hello,
I am developing a model for simulating experimental data sets. Each data set corresponds to two specific variables (P and T). The model is generally represented by the following equation:
V_total = V1 + V2 + A log (a/a1) + B log (a/a2)
where a = 0:1.5:700;
The terms of V1, V2, A and B are calculated through specific equations so you can consider them constants. The coefficients of a1 and a2 are functions of P and T as follows:
a1 = x1 * P^0.5 * exp(16.95 - (5052 / T))
a2 = x2 * P^0.5 * exp(8.47 - (2526 / T))
For each data set, I want to obtain the best fitting by optimising coefficients x1 and x2.
For better understanding, here is a plot of the data set of P = 5 & T = 90. I randomly used x1 = 0.1 and x2 = 0.005.
I would be grateful if someone helps me in solving this issue.
Thank you in advance.
2 个评论
the cyclist
2024-5-17
Can you upload one or two example datasets? You can use the paper clip icon in the INSERT section of the toolbar.
回答(1 个)
Star Strider
2024-5-17
Perhaps something like this —
T1 = readtable('Ask_17.05.2024.xlsx')
a = T1.a;
a(1) = 1E-4; % Please Avoid Calculating 'log(0)'
V_total = T1.V_total;
P = 5;
T = 90 + 273
V1 = rand; % Provide Missing Value
V2 = rand; % Provide Missing Value
A = rand; % Provide Missing Value
B = rand; % Provide Missing Value
a1 = @(x,a) x(1) * sqrt(P) * exp(16.95 - (5052 / T));
a2 = @(x,a) x(2) * sqrt(P) * exp(8.47 - (2526 / T));
V_total_fcn = @(x,a) V1 + V2 + A*log(a/a1(x,a)) + B*log(a/a2(x,a))
x0 = rand(2,1);
X = lsqcurvefit(V_total_fcn, x0, a, V_total)
figure
plot(a, V_total, '.', 'DisplayName','Data')
hold on
plot(a, V_total_fcn(X,a), '-r', 'DisplayName','Regression Fit')
hold off
grid
xlabel('a')
ylabel('V\_total')
legend('Location','best')
This may work without further changes with the correct values for ‘V1’, ‘v2’, ‘A’, and ‘B’, however it may be necessary to use the real, imag, or abs functions to deal with the complex results if they persist after that.
.
5 个评论
Star Strider
2024-5-21
My revised code (edited a few minutes ago in my previous Comment) implements the genetic algorithm (ga), and the additional assignments define the fitness function ‘ftns’ and the options structure I use with my ga calls.
I did not previously correct my code because I could not run it, so there are several obvious errors.. The current version runs and gives a reasonable result. I added a fitnlm call both to provide statistics on the parameters and the fit, and to tweak the parameters to give the best result. (The ga function actually has a version of this as part of its options and refers to it as a hybrid parameter estimation.)
There may still be some differences in the estiamted parameters between the runs, however they should be within the confidence intervals for any set of estimated parameters. The fit in general is quite good.
.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!