MATLAB: Fsolve- stopped because last step was ineffective.

fsolve-no solution

My function looks like this:
function f=myfun1(x)
in1=[ -0.7173;1.0000;-1.0000];
outx= -0.1096;
f=[outx(1)-x(2)*0.1161+x(3)*0.0051+x(4)*0.3253+x(5)*-0.7701-1.3146;
(x(2)*(1+exp(-2*(1.3694*in1(1)-0.1548*x(1)-9.9633*in1(3)+4.5337)))/2)+1;
(x(3)*(1+exp(-2*(1.3361*in1(1)+6.1981*x(1)+6.8760*in1(3)-3.7009)))/2)+1;
(x(4)*(1+exp(-2*(-3.1075*in1(1)-0.1217*x(1)-2.3413*in1(3)-1.9678)))/2)+1;
(x(5)*(1+exp(-2*(-0.4107*in1(1)-4.6607*x(1)-1.1428*in1(3)-7.3723)))/2)+1];
end
x0=2*rand(5,1)-1;-random initial values of the range[-1,1] was considered.
options = optimset('Display','iter','MaxFunEvals',10000);
[x,fval] = fsolve(@myfun1,x0,options);
Initially, the solver stopped prematurely so I set 'MaxfunEvals' to 10000, but now i get the following error:\\ "fsolve stopped because the last step was ineffective. However, the vector of function values is not near zero, as measured by the default value of the function tolerance."
Alternatively, I tried using different representation of the same function:
function f=myfun(x)
in1=[ -0.7173;1.0000;-1.0000];
outx= -0.1096;
f=[outx(1)-x(2)*0.1161+x(3)*0.0051+x(4)*0.3253+x(5)*-0.7701-1.3146;
x(2)-tansig(1.3694*in1(1)-0.1548*x(1)-9.9633*in1(3)+4.5337);
x(3)-tansig(1.3361*in1(1)+6.1981*x(1)+6.8760*in1(3)-3.7009);
x(4)-tansig(-3.1075*in1(1)-0.1217*x(1)-2.3413*in1(3)-1.9678);
x(5)-tansig(-0.4107*in1(1)-4.6607*x(1)-1.1428*in1(3)-7.3723)];
end
In this case too, fsolve does not give any solution. The above function is essentially an ann function, where x(1) is an input to ann; x(2)..x(5) are the activation functions; outx is the output. ANN was initially trained for known values of x(1) and the corresponding x(2),x(3),x(4),x(5) and outx were obtained. I have used the above function in an optimization problem with x(1) now fixed as unknown and outx as known parameter. Given that, there has to be solution for x(1) since the original function has just been reversed. Further, it has 5 equations and 5 unknowns but i do not know where does the problem lie. Further, I tried to solve using fmincon:
function [c ceq]=fminconstr(x)
c=[];
ceq=myfun1(x);
rng('default')
x0=2*rand(5,1)-1;
lb=[-1; -1; -1; -1; -1];
ub=[1; 1; 1; 1; 1];
%%opts = optimset('Display','on');
x= fmincon(@(x)0,x0,[],[],[],[],lb,ub,@fminconstr);
x0=2*rand(5,1)-1;
Can someone please help me. Thank you in advance.

Best Answer

ANN was initially trained for known values of x(1) and the corresponding x(2),x(3),x(4),x(5) and outx were obtained. I have used the above function in an optimization problem with x(1) now fixed as unknown and outx as known parameter.
That means you know what the correct solution is supposed to be. Did you plug the expected solution x into your implementation of myfun1() to sanity-check that myfun1(x)=0 is satisfied? You should do so, and also show us the correct values of x so that we can do the same, and convince ourselves that a solution does indeed exist.
For now, I am pretty confident that your first system of equations, as you've shown them to us above, does not have a solution. I guess you know that your objective function is linear in all but x(1) and that the other x(i) are determined by linear equations once x(1) is fixed. Therefore, your problem simplifies to minimizing the scalar cost function below as a function of x1. However, when I plot this cost function over large ranges of x1, I can't see it get near zero anywhere.
function f=myfun2(x1)
in1=[ -0.7173;1.0000;-1.0000];
outx= -0.1096;
d1=(1+exp(-2*(1.3694*in1(1)-0.1548*x1-9.9633*in1(3)+4.5337)))/2;
d2=(1+exp(-2*(1.3361*in1(1)+6.1981*x1+6.8760*in1(3)-3.7009)))/2;
d3=(1+exp(-2*(-3.1075*in1(1)-0.1217*x1-2.3413*in1(3)-1.9678)))/2;
d4=(1+exp(-2*(-0.4107*in1(1)-4.6607*x1-1.1428*in1(3)-7.3723)))/2;
A=[-0.1161, 0.0051 ,0.3253, -0.7701;
d1 0 0 0;
0 d2 0 0;
0 0 d3 0;
0 0 0 d4];
b=-[outx(1)-1.3146 ; 1;1;1;1];
f=norm(A*(pinv(A)*b)-b).^2;