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]; endx0=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