Optimization Curve Fitting: Curves are not converging
Afficher commentaires plus anciens
I'm trying to fit some experimental data with a mathemtical model. I'm trying to using Optimization techiques to do the fitting, namely "fminsearch, and fmincon". However, and as you can see in the attcahed plot image, the cuvres do not match. They do some how have simlar shaeps, and tried to follow MATLAB's guide on the topic as well.
My fitting parametres are:
- Q. (Highest Priority)
- Total (2nd Highest)
- S1 and 2.
- Tep.
I have attached my sample data along with my code. It takes a little while to run but it works. Looking forward for your help, and thank you in advance.
6 commentaires
Matt J
le 8 Fév 2023
and as you can see in the attcahed plot image
There is no image attachment at the time I'm writing this.
Trung
le 8 Fév 2023
Matt J
le 8 Fév 2023
It takes a little while to run but it works.
The time consuming part is the calculation of Pre. I urge you to make life easy on us and just attach that, along with the other fixed problem parameters, in a .mat file. Then we can jump straight to the optimization.
Trung
le 8 Fév 2023
Thanks you for that part, but the calculation of Pre is still quite slow and it is unnecessary for your question to have us repeat it. If you have already done the part below, then just attach all these pre-calculated variables in a .mat fil (one file, not several).
Experiment = importdata('Data.txt');
Real_Time = Experiment(:,1);
Real_Pre = Experiment(:,2);
%If it is taking so long, this will make it faster
% Real_Time = downsample(Experiment(:,1),20); %s
% Real_Pre = downsample(Experiment(:,2),20); %Torr
Qp = 10;
Total=8e16;
Tim= Real_Time;
S1= 15;
S2=50;
Tep= 293;
Pre=Fitt_Test(Qp,Total,Tim,S1,S2,Tep);
Trung
le 8 Fév 2023
Réponses (1)
One immediate problem that I see is that in sseval, the optimization variables x(i) aren't used at all in the calculation of sse. That's what the squiggly red underlines are trying to warn you of:

16 commentaires
Trung
le 8 Fév 2023
Matt J
le 9 Fév 2023
since the x has no use
The x is the important part. It's what the solver is trying to find. So, the sse has to depend on it.
Trung
le 9 Fév 2023
Yes but Pre must be computed inside sseval() and it must be computed based on x, which is what fmincon is passing to sseval through fun(). In your current implementation, Pre is just some fixed variable that gets passed to sseval every time fmincon calls it. We can see this by calling fun() several times with random inputs. The output is always the same:
load Fit.mat
fun = @(x)sseval(x,Tim,Real_Pre,Pre);
fun(rand(5,1))
fun(rand(5,1))
fun(rand(5,1))
function sse = sseval(x,Tim,Pre,Real_Pre)
Eng = x(1);
Molec = x(2);
Sped1 = x(3);
Sped2 = x(4);
Tempre = x(5);
% sse = sum((Pre - Real_Pre).^2);
sse = sqrt(mean((Pre-Real_Pre).^2));
end
Trung
le 9 Fév 2023
Matt J
le 9 Fév 2023
Well done!
Trung
le 9 Fév 2023
Trung
le 9 Fév 2023
Trung
le 9 Fév 2023
Matt J
le 9 Fév 2023
There's nothing we can do to help you without understanding the prediction model.
Matt J
le 9 Fév 2023
This looks like a 2-parameter problem
and
. Not sure how you got to 5 unknowns. If there are only 2 unknowns, you can probably do an exhaustive search for the optimal solution.
Trung
le 9 Fév 2023
Maybe you didn't understand what I meant by "do an exhaustive search". Since you now have only 2 unknown variables, you can use surf() to plot sseval as a 2D surface and see where its minimum lies. If desired, you could then run fmincon with the initial guess x0 chosen to lie where the minimum appears to be on the surf plot.
Trung
le 9 Fév 2023
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



