Failure in initial objective function evaluation. FSOLVE cannot continue [closed]

Publish date: 2024-05-04

I have this code:

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 function [Y] = Func(X,B,E,F,Q0,Q1) Y= B-((Q1-Q0*exp(X))./(E+((E*X+F)*(0.5+(X./6)+((X.^2)/24))))); end 

When I run it, it says:

Failure in initial objective function evaluation. FSOLVE cannot continue.

1

1 Answer

Your matrix dimensions do not agree, you can see that if you just call Func with your X0.

Is Func supposed to return a scalar or a vector? If it is supposed to return a vector, then perhaps you meant to use element multiplication (.*) rather than matrix multiplication (*)?

B-((Q1-Q0.*exp(X))./(E+((E.*X+F).*(0.5+(X./6)+((X.^2)/24))))) 

If Func is to return a scalar then you need to think about the vector dimensions and transpose (') some of your variables.

0

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobHFwZ26Fd4WOn5iipKWnsm61zWagp6Gknq6tec6boZ6bpJ7DpnnFrqWcrJmku26x1ZqjrpmknryvecWspqWulWKworrNqKtmm5%2Bjwaq61J4%3D