Optimization Curve Fitting: Curves are not converging
이전 댓글 표시
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
Matt J
2023년 2월 8일
and as you can see in the attcahed plot image
There is no image attachment at the time I'm writing this.
Trung
2023년 2월 8일
Matt J
2023년 2월 8일
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
2023년 2월 8일
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
2023년 2월 8일
답변 (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
Trung
2023년 2월 8일
Matt J
2023년 2월 9일
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
2023년 2월 9일
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
2023년 2월 9일
Matt J
2023년 2월 9일
Well done!
Trung
2023년 2월 9일
Trung
2023년 2월 9일
Trung
2023년 2월 9일
Matt J
2023년 2월 9일
There's nothing we can do to help you without understanding the prediction model.
Matt J
2023년 2월 9일
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
2023년 2월 9일
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
2023년 2월 9일
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



