Failure in initial objective function evaluation. FSOLVE cannot continue.

3 次查看(过去 30 天)
I am having this problem in MATLAB.
B=[0,0.0574612898073843,0.110961034961411,0.157844338275811,0.198326084545702,0.233505068208522,0.264466281579592,0.291951607426117,0.316302322044398,0.337552164906992,0.355641291820062]; E=[0.00821682460973364,0.0230168805223958,0.0353571800836649,0.0452377232935416,0.0526585101520253,0.0576195406591166,0.0601208148148149,0.0601623326191205,0.0577440940720333,0.0528660991735539,0.0454999999999998]; F=[0.0789623507805327,0.0592582389552085,0.0395296398326703,0.0197765534129168,-1.02030405058073e-06,-0.0198030813182328,-0.0396296296296297,-0.0594806652382411,-0.0793561881440668,-0.0992561983471074,-0.119200000000000]; Q0=[0.248000000000000,0.256216824609734,0.279233705132129,0.314590885215794,0.359828608509336,0.412487118661361,0.470106659320478,0.530227474135293,0.590389806754413,0.648133900826446,0.701000000000000]; Q1=[0.448000000000000,0.535179175390266,0.617454294867871,0.692341114784206,0.757355391490664,0.810012881338639,0.847829340679523,0.868320525864708,0.869002193245587,0.847390099173554,0.801000000000000];
X0=ones(1,11); A=fsolve(@(X)Func(X,B,E,F,Q0,Q1),X0,optimoptions('fsolve','Display','iter','MaxIterations',10000,'MaxFunctionEvaluations',50000,'FunctionTolerance',10^-8,'Diagnostic','on'));
tmp = -((Q1-Q0*exp(A))./(E+((EA+F)(0.5+(A./6)+((A.^2)/24))))); differenza=B+tmp
function [Y] = Func(X,B,E,F,Q0,Q1) Y= B-((Q1-Q0*exp(X))./(E+((EX+F)(0.5+(X./6)+((X.^2)/24))))); end
When I run it , it says:
Failure in initial objective function evaluation. FSOLVE cannot continue.
CAN ANYONE HELP ME, PLEASE?

回答(1 个)

Star Strider
Star Strider 2019-11-15
The ‘Y’ evaluation is missing a few multiplication(?) operators, and needs to do element-wise operations elsewhere:
Y = B-((Q1-Q0*exp(X))./(E+((EX+F)(0.5+(X./6)+((X.^2)/24)))));
Rewriting ‘Func’ as an anonymous function and correcting those (and similar errors in ‘tmp’):
Func = @(X,B,E,F,Q0,Q1) B-((Q1-Q0.*exp(X))./(E+((E.*X+F).*(0.5+(X./6)+((X.^2)/24)))));
as well as making your code actually readable:
Func = @(X,B,E,F,Q0,Q1) B-((Q1-Q0.*exp(X))./(E+((E.*X+F).*(0.5+(X./6)+((X.^2)/24)))));
B=[0,0.0574612898073843,0.110961034961411,0.157844338275811,0.198326084545702,0.233505068208522,0.264466281579592,0.291951607426117,0.316302322044398,0.337552164906992,0.355641291820062];
E=[0.00821682460973364,0.0230168805223958,0.0353571800836649,0.0452377232935416,0.0526585101520253,0.0576195406591166,0.0601208148148149,0.0601623326191205,0.0577440940720333,0.0528660991735539,0.0454999999999998];
F=[0.0789623507805327,0.0592582389552085,0.0395296398326703,0.0197765534129168,-1.02030405058073e-06,-0.0198030813182328,-0.0396296296296297,-0.0594806652382411,-0.0793561881440668,-0.0992561983471074,-0.119200000000000];
Q0=[0.248000000000000,0.256216824609734,0.279233705132129,0.314590885215794,0.359828608509336,0.412487118661361,0.470106659320478,0.530227474135293,0.590389806754413,0.648133900826446,0.701000000000000];
Q1=[0.448000000000000,0.535179175390266,0.617454294867871,0.692341114784206,0.757355391490664,0.810012881338639,0.847829340679523,0.868320525864708,0.869002193245587,0.847390099173554,0.801000000000000];
X0=ones(1,11);
A=fsolve(@(X)Func(X,B,E,F,Q0,Q1),X0,optimoptions('fsolve','Display','iter','MaxIterations',10000,'MaxFunctionEvaluations',50000,'FunctionTolerance',10^-8,'Diagnostic','on'));
tmp = -((Q1-Q0.*exp(A))./(E+((E.*A+F).*(0.5+(A./6)+((A.^2)/24)))));
differenza=B+tmp
produces:
A =
0.59136 0.72882 0.7792 0.77019 0.7238 0.6548 0.5718 0.479 0.37742 0.26558 0.13939

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by