Hi everyone. I am trying to solve a group of nonlinear equations. It supposes to return a matrix, but the error keeps appearing.
Any advice or suggestion is appreciated.
Index in position 3 exceeds array bounds (must not exceed 1).Error in Untitled8>myfun (line 20) F=[1/ds*(y(:,:,3)+M11)*(y(:,:,1)-y11)...Error in fsolve (line 242) fuser = feval(funfcn{3},x,varargin{:});Error in Untitled8 (line 5)[x,fval]=fsolve(@myfun,x0);Caused by: Failure in initial objective function evaluation. FSOLVE cannot continue. clear all clc a=randi(6,6) x0=[a;a;a;a;a;a;a;a]; [x,fval]=fsolve(@myfun,x0); function F = myfun(y) ds=1;dt=1; M11=randi(6,6); N11=randi(6,6); Q11=randi(6,6); y11=randi(6,6); M21=randi(6,6); N21=randi(6,6); Q21=randi(6,6); y21=randi(6,6); F=[1/ds*(y(:,:,3)+M11)*(y(:,:,1)-y11)... +1/ds*(y(:,:,4)+M21)*(y(:,:,2)-y21)... -1/dt*(N21+N11)*(y21-y11)... -1/dt*(y(:,:,5)+y(:,:,6))*(y(:,:,2)-y(:,:,1))... -Q11-y(:,:,7)-Q21-y(:,:,8);]; end
Best Answer