cant get a good fit

3 views (last 30 days)
Thaer Ismail
Thaer Ismail on 8 Jan 2020
Answered: Walter Roberson on 8 Jan 2020
I cannot get a good fit. Attache is the data that I am using . Is there any other method to fit the data better
Thank you.
raw = xlsread('Dummy data canada'); % read in sheet number
Pc = raw(23:118,1);
Sw = raw(23:118,4)/100; %to convert Sw to fraction
plot(Sw,Pc,'ro')
F = @(x,xdata)1-x(1)*exp(-(x(2)./xdata).^(x(3)));
x0 = [-23124 0.3 -2.2];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,Sw,Pc)
hold on
plot(Sw,F(x,Pc))
hold off
Capture.JPG
output =
struct with fields:
firstorderopt: 3.5903e+05
iterations: 16
funcCount: 68
cgiterations: 0
algorithm: 'trust-region-reflective'
stepsize: 2.0413
message: '↵Local minimum possible.↵↵lsqcurvefit stopped because the final change in the sum of squares relative to ↵its initial value is less than the value of the function tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the relative sum of squares (r) is changing↵by less than options.FunctionTolerance = 1.000000e-06.↵↵'
  1 Comment
Thaer Ismail
Thaer Ismail on 8 Jan 2020
Even using simple forms doesnt work
F = @(x,xdata) exp(x(1)+x(2)*xdata)
x0 = [10 10]
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,Sw,H)
%
Capture.JPG
output =
struct with fields:
firstorderopt: 4.2501
iterations: 26
funcCount: 81
cgiterations: 0
algorithm: 'trust-region-reflective'
stepsize: 7.9310e-04
message: '↵Local minimum possible.↵↵lsqcurvefit stopped because the final change in the sum of squares relative to ↵its initial value is less than the value of the function tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the relative sum of squares (r) is changing↵by less than options.FunctionTolerance = 1.000000e-06.↵↵'

Sign in to comment.

Answers (2)

Robert U
Robert U on 8 Jan 2020
Hi Thaer Ismail,
the following plot command is not correct:
plot(Sw,F(x,Pc))
According to your data handling it should be
plot(Sw,F(x,Sw))
resulting in expected fit-function outcome.
Kind regards,
Robert

Walter Roberson
Walter Roberson on 8 Jan 2020
My tests with other minimizers suggest that the values you are getting are within error tolerance of the best you can get with that model and that data.
If you construct the residue function then it is possible to differentiate with respect to x(1) and solve that for x(1), and then substitute, reducing the residue function to an equation of two variables -- so knowing x(2) and x(3) you can directly calculate the best x(1) . For the experimental values of x(2) and x(3) I was getting, the experimental x(1) value matched the optimum (so the search routines were working.)
Unfortunately it is not feasible to continue onward with differentiating the residue function of two variables. It is possible, though, to plot some points on its surface, to check to see if the experimental values are reasonable.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!