How to use multiple sets of xDATA with lsqcurvefit?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have following function

I'd like to get coefficients alpha, beta, gamma, delta and epsilon coefficients by least squares method and use it to fit some data.
So, I have 3 sets of xDATA (for every independent variable) and one set of yData (for dependent variable) and I'd like to put it all into lsqcurvefit function.
f = @(c, x) c(1).*x(:,2).^(c(2).*x(:,1).^c(3)) + (c(4) + c(5).*x(:,1))./x(:,3);
and to use it like this
lsqcurvefit(f, [1 1 1], [ndoms nDOF nprocs], measuredVals)
but, unfortunately, I'm still getting following error:
Index exceeds matrix dimensions.
Error in factorizatonKGlobRegr>@(c,x)c(1).*x(:,2).^(c(2).*x(:,1).^c(3))+(c(4)+c(5).*x(:,1))./x(:,3)
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
What am I doing wrong?
---------------------------------------------------
Data
measuredVals = [
0.1647815
0.06300775
0.05769325
0.04803725
0.04290825
0.0405065
0.03807525
0.03487725
0.284112
0.13495675
0.12740075
0.11109725
0.105036
0.11022575
0.100587
0.09803775
0.48695475
0.30563525
0.30084925
0.283312
0.2745085
0.271998
0.27472625
0.27103925
0.89953925
0.68234025
0.6783635
0.65540225
0.64421475
0.64214725
0.63949875
0.623119
1.588605
1.37335275
1.36082075
1.35097375
1.34813125
1.34932025
1.3519095
1.34521625
2.820884
2.63251325
2.640659
2.6338805
2.636361
2.62748
2.6233345
2.63821
4.81472975
4.65116425
4.664892
4.64225625
4.6734825
4.63981675
4.635483
4.6280245];
n = 56;
ndoms = [];
for i=1:n
ndoms = [ndoms; 288];
end
tmp = [
375
1029
2187
3993
6591
10125
14739];
nDOF = [];
for i=1:7
for j=1:8
nDOF = [
nDOF
tmp(i)];
end
end
nprocs = [];
for i=1:7
nprocs = [nprocs; [1 2 3 4 6 8 12 24]'];
end
1 Kommentar
Dean
am 19 Mär. 2018
Hi Martin,
I have discovered your issue as I have the same problem you had a while ago. I was wondering if you have an idea, how to plot the data sets and the fitted cruve in a plot in order to show the fitting accuracy as it is done in the graphic attached below. The xdata set consists in my case of two different vectors, that I implement in my curve fitting. Each vectors has a different magnitude. Can help me with this issue?
Kind regards
Dean
Antworten (1)
Alan Weiss
am 14 Feb. 2017
Thanks you for giving such a complete, detailed question. Your error is clear. Your objective function takes a 5-D variable c:
f = @(c, x) c(1).*x(:,2).^(c(2).*x(:,1).^c(3)) + (c(4) + c(5).*x(:,1))./x(:,3);
However, your initial point x0 is 3-D:
minc = lsqcurvefit(f, [1 1 1], [ndoms nDOF nprocs], measuredVals)
Give a 5-D initial guess, such as rand(5,1), or ones(5,1).
And, in the future, you might want to learn how to use repmat and ones to save yourself some for loops.
Alan Weiss
MATLAB mathematical toolbox documentation
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!