# Failure in initial objective function evaluation. FSOLVE cannot continue.

5 views (last 30 days)

Edited: 奥 刘 on 12 Nov 2021
Recently, i'm trying to solve a nonlinear equation set by using "fsolve" . I created my personal function as the following:
function F = poSTAR_14(x,Hm_RI,at_RI,J)
F(1)=Hm_RI*x;
F(2)=at_RI*x-[1;0];
F(3)=abs(x(1:32,1)).^2+abs(x(33:64,1)).^2-ones(J,1);
end
Above is the function that contains 3 nonlinear equations and I saved it as a .m file with my main file.
Below is the part that I call the fsolve to solve my problem, where , are known vetors, is known scalar, initial point
Hm_R=real(Hm).*100;
Hm_I=imag(Hm).*100;
Hm_RI=[Hm_R,-Hm_I;Hm_R,Hm_I];
at_R=real(as_ele_Tx.');
at_I=imag(as_ele_Tx.');
at_RI=[at_R,-at_I;at_R,at_I];
w_R=real(conj(W_Tx));
w_I=imag(conj(W_Tx));
fun = @poSTAR_14;
x0 = [w_R;w_I];
x = fsolve(@(x)fun(x,Hm_RI,at_RI,J),x0);
But something is wrong with my code and It seems someting wrong with the size of my matrix in the problem formulation:
Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.
Error in poSTAR_14 (line 2)
F(1)=Hm_RI*x;
Error in fsolve_PO>@(x)fun(x,Hm_RI,at_RI,J) (line 202)
x = fsolve(@(x)fun(x,Hm_RI,at_RI,J),x0);
Error in fsolve (line 248)
fuser = feval(funfcn{3},x,varargin{:});
Error in fsolve_PO (line 202)
x = fsolve(@(x)fun(x,Hm_RI,at_RI,J),x0);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

@Jon Thanks for your help! I have solved this problem.

Matt J on 11 Nov 2021
Edited: Matt J on 11 Nov 2021
function F = poSTAR_14(x,Hm_RI,at_RI,J)
F1=Hm_RI*x;
F2=at_RI*x-[1;0];
F3=abs(x(1:32,1)).^2+abs(x(33:64,1)).^2-ones(J,1); %The abs() seems unnecessary here
F=[F1(:);F2(:);F3(:)];
end

@Matt J Thanks! Now I know why I am wrong.

### Categories

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by