Maximum number of function evaluations has been exceeded error. MaxFunEvals was increased, but I cannot solve the problem.
7 次查看(过去 30 天)
显示 更早的评论
I have a code as below. It gives a warning. "Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 16932.059934". I increased the MaxFunEvals, how can I optimize the constants in equation with a code?
How can I solve this problem? I am very new in Matlab.
% My code to solve an empirical equation
v = xlsread('I:\Yeni klasör\Tez 30 temmuz\Tez kilitlenme\Türkiye\Kahramanmaraş\matlab model.xlsx')
z=v(:,1)
y=v(:,2)
x=v(:,6)
u=v(:,10)
syms a, syms b, syms c, syms d, syms e
p(1) = a, p(2) = b, p(3) = c, p(4)=d, p(5)=e
z = @(p,v) v(:,2).*(p(1).* v(:,10)+ p(2).* v(:,6)+ p(3).* v(:,6).^2+ p(4).* v(:,6).* v(:,10)+ p(5))
P0 = [-0,944; 0,3798; -0,05369; 0,2164; 0,064]; % Choose Appropriate Initial Parameter Estimates
SSECF = @(p) sum((v(:,1) - z(p,v)).^2); % Sum-Squared-Error Cost Function
options = optimset('MaxFunEvals',100000000000000);
options = optimset('MaxIter',10000000000000000);
[abc, SSE] = fminsearch(SSECF, P0, options); % Estimate Parameters
a = abc(1)
b = abc(2)
c = abc(3)
d = abc(4)
e = abc(5)
0 个评论
采纳的回答
John D'Errico
2016-9-10
编辑:John D'Errico
2016-9-10
This is a linear least squares problem. Why in the name of god and little green apples are you using symbolic variables, and fminsearch? Then you set the max number of function evals to 100000000000000? How many zeros is that? 14? ROFLMAO.
My guess is this is an ill-conditioned problem, which caused fminsearch to have difficulties. But since I don't have your data, how can I know?
n = size(v,1);
M = [v(:,10), v(:,6), v(:,6).^2, v(:,6).*v(:,10) ,ones(n,1)];
M = bsxfun(@times,v(:,2),M);
Now there are lots of ways to solve for the coefficients in MATLAB. All are far better than the poor scheme used above. Pick any of the three that follow. The last one below may be the best choice if you have conditioning problems.
abc = M\v(:,1);
abc = lsqr(M,v(:,1));
abc = pinv(M)*v(:,1);
Or you could have used my polyfitn, found on the file exchange.
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!