Nonlinear equations with Jacobian
Show older comments
Hi I am trying to solve a system of nonlinear equations with Jacobean provided. I solved the system with the Jacobean approximated with finite difference methods. However, I could not do it with the jacobean provided. the structure I followed is
function [y, JAC] =finalmodyld20002d_withjac(x) y = zeros (8, 1);
y(1)=(abs(((2/3)*x(1)+(1/3)*x(2))).^a)+... ((abs((2/3)*x(3)-(2/3)*x(4))).^a)+... ((abs((4/3)*x(5)-(x(6)/3))).^a)-... 2*(equivsigma/sigma0).^a; y(2)=... y(3)=... y(4)=... y(5)=... y(6)=... y(7)=... y(8)=...
if (nargout == 8)
JAC = zeros (8, 8);
% end function JAC(1,1)=(16*abs((2*x(1))/3 + x(2)/3)^7*sign((2*x(1))/3 + x(2)/3))/3; JAC(1,2)=(8*abs((2*x(1))/3 + x(2)/3)^7*sign((2*x(1))/3 + x(2)/3))/3; JAC(1,3)=(16*abs((2*x(3))/3 - (2*x(4))/3)^7*sign((2*x(3))/3 - (2*x(4))/3))/3; JAC(1,4)=-(16*abs((2*x(3))/3 - (2*x(4))/3)^7*sign((2*x(3))/3 - (2*x(4))/3))/3; JAC(1,5)=-(32*abs(x(6)/3 - (4*x(5))/3)^7*sign(x(6)/3 - (4*x(5))/3))/3; JAC(1,6)=(8*abs(x(6)/3 - (4*x(5))/3)^7*sign(x(6)/3 - (4*x(5))/3))/3; JAC(1,7)=0; JAC(1,8)=0;
%%% JAC(2,1)= ... JAC(2,2)= JAC(2,3)= JAC(2,4)= JAC(2,5)= JAC(2,6)= JAC(2,7)=0; JAC(2,8)=0;
continue for other elements in the 8x8 jaconean
%%%
end
end
after I constructed the function with its Jacobean, I run x0=[0.23;1.3;1.6;1.3;2.4;1;1.3;3]; options = optimoptions('fsolve','Display','iter','Algorithm','trust-region dogleg','FinDiffType','central','Jacobian','on'); [x,iter,fval]= fsolve(@finalmodyld20002d_withjac, x0,options)
But the following error shows:
Error using feval Output argument "JAC" (and maybe others) not assigned during call to "C:\Users\Hamzah Alharthi\Documents\MATLAB\finalmodyld20002d_withjac.m>finalmodyld20002d_withjac".
Error in fsolve (line 228) [fuser,JAC] = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
could you please help solving this issue?
Hamzah
Answers (1)
Torsten
on 8 Apr 2015
0 votes
Take a look at the example under
You will have to replace
if (nargout == 8)
by
if nargout > 1,
I guess.
Best wishes
Torsten.
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!