필터 지우기
필터 지우기

Subscript indices must either be real positive integers or logicals. FSOLVE PROBLEM

조회 수: 2 (최근 30일)
Hi everyone! I get this error message and I thought I might have forgotten a * sign, but apparently it isn't so. What could be wrong?
Main:
% fsolve caller
aaaa=fsolve(@(Z) base_montante(Z,vet_1_base_montante,vet_2_base_montante),-ex_1);
function with vector of equations:
function F = base_montante(Z,vet_1_base_montante,vet_2_base_montante)
vet_3_base_montante=zeros(3,1);
ex_1=[1;
0;
0];
vet_3_base_montante(1)=Z(1);
vet_3_base_montante(2)=Z(2);
vet_3_base_montante(3)=Z(3);
F=[dot(vet_3_base_montante,vet_1_base_montante);
dot(vet_3_base_montante,vet_2_base_montante);
dot(vet_3_base_montante,-ex_1)-1];
vet_1_base_montante , ex, and vet_2_base_montante are pre-assigned vectors, so it should solve for the 3 components of vet_3_base_montante...
Here's the complete error message, though only the first line should be the cause for it all:
Subscript indices must either be real positive integers or logicals.
Error in @(Z)base_montante(Z,vet_1_base_montante,vet_2_base_montante)
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

채택된 답변

Francesco Ardia
Francesco Ardia 2017년 4월 4일
Ok, found it. I created a matrix and gave it the same name as this function, so when running the code again without clearing the memory first, Matlab of course didn't accept the function's inputs as valid indices for the matrix...

추가 답변 (1개)

Jan
Jan 2017년 4월 3일
I have no idea. What does the debugger reveal? Type this in the command window:
dbstop if error
Now run you code. Where does it stop? What are the values of the variables used in this line?
  댓글 수: 1
Francesco Ardia
Francesco Ardia 2017년 4월 4일
New comment: if I type "clear all" and run the code again, I get no error message and the results make sense. If I run it again, I get the same error I reported. By typing the dbstop line, the debugger brings me to the "fsolve" code, and apparently there's a problem with the Jacobian, as what makes the code stop is at line 224 (little green arrow). But I don't know what that's about...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by