I am getting this error while solving "fsolve stopped because it exceeded the function evaluation limit,

3 次查看(过去 30 天)
file 1
% model 2 main part, cal & plot
tic;
N = 10; % N = 20
lambda = 0.1:1;
S = [1:50];
PL = 1024;
for i = 1:50
x0 = [1; 1; 1; 0; 1; 0; 1346; 0.0027]; % wired start point
options = optimoptions('fsolve');
[x,fval] = fsolve(@(x)m2_numeric_solver2(x,N,lambda(i)),x0,options);
Data = x(5) * x(6) * PL;
Time = x(7);
S(i) = (Data / Time)/10^6;
formatSpec = 'iteration %d complete\n';
fprintf(formatSpec,i)
end
plot(S);
title('Unsaturation throughput vs arrival rate');
xlabel('arrival rate');
ylabel('saturation throughput');
grid on;
toc;
file 2
% model 2 numberic solver with capture effct and error rate
% x(1) -- tao
% x(2) -- Pcol
% x(3) -- Peq
% x(4) -- Pcap
% x(5) -- Pt
% x(6) -- Ps
% x(7) -- E[T]
% x(8) -- q
% notice: warning i, confuse with complex 'i'
% notice: double for symsum
function F = m2_numeric_solver2(x,N,lambda)
syms k;
z = 4; % << capture threshold
W = 32;
m = 5;
Pe = 0.01; % << channel error rate
tao = 1/(10^6);
Ts = 1140/(10^6);
Tc = 1364/(10^6);
Te = 1364/(10^6);
F = [
x(1) - 2*(1-2*x(3))*x(8) / ( x(8)*( (W+1)*(1-2*x(3)) + W*x(3)*(1 - (2*x(3))^m)) ...
+ 2 * (1-x(8)) * (1-x(3)) * (1-2*x(3)) );
x(2) - ( 1 - (1-x(1)) ^ (N-1) - x(4) );
x(3) - ( x(2) + Pe - Pe*x(2) );
x(4) - double( symsum( nchoosek(N,k+1) * x(1)^(k+1)*(1-x(1))^(N-k-1) / (1+z)^k, 1, N-1) );
x(5) - (1 - (1 - x(1))^N);
x(6) - (N*x(1)*(1-x(1))^(N-1) + x(4)) / x(5);
x(7) - ( (1-x(5))*tao + x(5)*(1-x(6))*Tc + x(5)*x(6)*Pe*Te + + x(5)*x(6)*(1-Pe)*Ts );
x(8) - (1 - exp(-lambda*x(7)) );
];
end

采纳的回答

Walter Roberson
Walter Roberson 2017-8-18
options = optimoptions('fsolve');
options.MaxIterations = 1000;
options.MaxFunctionEvaluations = 5000;

更多回答(1 个)

Alan Weiss
Alan Weiss 2017-8-18
You wrote
lambda = 0.1:1;
This gives the same value as
lambda = 0.1;
Later you call lambda(i) for i from 1 through 50. This makes no sense. Maybe you meant
lambda = linspace(0.1,1,50);
I would try to not use symbolic variables inside the objective function. If you really need them, perhaps use matlabFunction to convert any symbolic function into a numeric function before you use it. See Using Symbolic Mathematics with Optimization Toolbox™ Solvers.
One more thing: don't set options inside the for loop. Set them at the beginning, before the loop, because setting options is slow.
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by