Non linear fitting with 3 independent variables

조회 수: 9 (최근 30일)
Shubham
Shubham 2024년 5월 8일
댓글: Alex Sha 2024년 5월 10일
I have a dataset consisting of one dependent variable (K) and 3 independent variables (a, IL, Vf). I am trying to fit a function which could represent dependent variable with fair amount of accuracy.
I have attached the Data.mat file consisting of the dataset.
The form I am trying to fit is -
K = (A - B*IL - C*a)*(D*exp(-E*Vf))
LaTeX form:
initial guess could be - , , , ,
I want the optimised coefficients for the best fitting. How to do this in curve fitting app I was able to do 2 independent variables. I am not aware of how to do this.
Also if not this function how to find some other simple function/functional forms that could represent this data. In academic research lot of people find correlation like this.
load('Data.mat');
PS - Please don't suggest a polynomial type fit consisting of linear, square and interaction terms. As the aim is to have minimum coefficients ie simpler equation.
  댓글 수: 2
Torsten
Torsten 2024년 5월 8일
The D in your fitting function makes the problem overfitted - D must be absorbed in A, B and C.
Shubham
Shubham 2024년 5월 8일
D is redundant, anyway it will get multiplied. You can just remove that it was my mistake.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2024년 5월 8일
편집: Matt J 2024년 5월 8일
S=load('Data');
f=@(E,S)exp(-E.*S.Vf);
funlist={f, @(E,S) -S.IL.*f(E,S), @(E,S) -S.a.*f(E,S)};
[E,ABC]=fminspleas(funlist,2.65, S, S.K); %From File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/10093-fminspleas
[A,B,C,E]=deal(ABC(1), ABC(2), ABC(3),E)
A = 225.3644
B = 1.7663
C = 0.0471
E = 2.8195
pred=(A - B*S.IL - C*S.a).*exp(-E.*S.Vf);
[pred,is]=sort(pred);
h=plot([S.K(is),pred]); legend 'K Measured' 'K Fit'
[h.Marker]=deal('x','o');
  댓글 수: 2
Shubham
Shubham 2024년 5월 8일
Thanks a lot sir. One last question how to find good functions to fit this data. As the R2 value for this functional form is around 0.86 which is kind of poor. Aim is to get R2 value around 0.95.
Matt J
Matt J 2024년 5월 8일
편집: Matt J 2024년 5월 8일
Improving the model is something only you are qualified to do.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2024년 5월 8일
편집: Torsten 2024년 5월 8일
M = load("Data.mat");
fun = @(A,B,C,E)(A - B*M.IL - C*M.a).*exp(-E*M.Vf);
f = @(A,B,C,E) fun(A,B,C,E) - M.K;
A0 = 13.5*13.2;
B0 = 0.2*13.2;
C0 = 0.002*13.2;
E0 = 2.65;
z0 = [A0,B0,C0,E0];
sol = lsqnonlin(@(z)f(z(1),z(2),z(3),z(4)),z0)
Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
sol = 1x4
225.3648 1.7663 0.0471 2.8195
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = sol(1);
B = sol(2);
C = sol(3);
E = sol(4);
n = numel(M.IL);
hold on
plot(1:n,M.K,'ob')
plot(1:n,fun(A,B,C,E),'r')
hold off
  댓글 수: 7
Sam Chak
Sam Chak 2024년 5월 8일
Have you studied the amplitude of K and observed the patterns of IL, a, and Vf, before suggesting the use of an exponential decay function? The coefficients of the heaviside 'IL' and staircase 'a' have a lesser impact on K compared to the sawtooth-like wave 'Vf'.
The output signal K may or may not have the same frequency as the input signal Vf. It depends on the specific system and the nature of the relationship between K and Vf. Additionally, there may be a phase lag between the input Vf and output K signals, which can also vary depending on the system dynamics.
Could you find the peaks (crest and trough) of K and then identify two mathematical models that fit the upper and lower envelopes of K? The fitting model for K should be bounded by the mathematical models of the upper and lower envelopes. In fact, the fitting model can be a parametric function of the two envelopes.
Alex Sha
Alex Sha 2024년 5월 10일
@Shubham Your data looks very unreasonable,taking the first 12 sets of data as an example:
a IL Vf k
150 0 0.3 80.62278276
150 0 0.4 65.35516476
150 0 0.5 53.38355585
150 0 0.55 44.04684674
150 0 0.3 93.39806254
150 0 0.4 72.1188811
150 0 0.5 59.5095425
150 0 0.55 49.09761477
150 0 0.3 106.1160211
150 0 0.4 81.98023891
150 0 0.5 67.42473537
150 0 0.55 55.30916884
It can be seen clearly that the values of all "a" and "IL" are same, however, it is strange that the same "Vf" value corresponds to a completely different "k" value,for example, Vf=0.3, corresponded k are 80.62278276, 93.39806254 and 106.1160211, respectively.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by