COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### what.....i don't know what it happened!(index must be a positive integer or logical)

• Follow

Hello~
I'm beginner of numerical calculation with matlab.
I'm trying to solve a system of nonlinear equations by newton method.
(i.e. X(k+1) = X(k)-inv(jacobian(F(X(k)))*F(X(k))   )
but i don't know what this error message say.
( index must be a positive integer or logical. )
following is my code.
====================================
x=1.000000;
y=1.000000;
z=1.000000;
X=[x
y
z];
for n=1:1:10
fprintf('iteration check point  ++\n');
X=[x
y
z];
FX=[f1(x,y,z)
f2(x,y,z)
f3(x,y,z)];
DF=[f1x(x,y,z) f2x(x,y,z) f3x(x,y,z)
f1y(x,y,z) f2y(x,y,z) f3y(x,y,z)
f1z(x,y,z) f2z(x,y,z) f3z(x,y,z)];
H=inv(DF)*FX;
X=X-H;
x=X(1,1);
y=X(2,1);
z=X(3,1);
end
====================================
f1,f2,and f3 is a system of nonliear equtions(external function)
(f1: x*y-z^2-1=0
f2: x*y*z+y^2-x^2+2=0
f3: exp(x)+z-exp(y)+3)
and f1x means (df1/dx)(derivative function, for example.
When i run this mfile,
the error say that ( index must be a positive integer or logical.  FX=[f1(x,y,z) )
i know the jacobian function. i dont wanna use this fuction but use 'DF' matrix I made.

well.....any... is there somebody to help me.plz.....

 0

"JKA tom" <everjkahn@hanmail.net> wrote in message <hqjbo0$3qd$1@fred.mathworks.com>...

> When i run this mfile,
> the error say that ( index must be a positive integer or logical.  FX=[f1(x,y,z) )
>

That error happens if for some reason Matlab see F1 as (array) VARIABLE and not as FUNCTION. Are you sure you declare the function F1 properly, and it is not cleared or overshadowed by the variable having a same name? Use "WHICH F1" command to make a diagnostic.

Bruno

 0

>
> That error happens if for some reason Matlab see F1 as (array) VARIABLE and not as FUNCTION. Are you sure you declare the function F1 properly, and it is not cleared or overshadowed by the variable having a same name? Use "WHICH F1" command to make a diagnostic.
>
======
But... can you explain what i should do to solve this probem conctretely?
what does it mean to 'Use "WHICH F1" command to make a diagnostic'?

 0

>
> That error happens if for some reason Matlab see F1 as (array) VARIABLE and not as FUNCTION. Are you sure you declare the function F1 properly, and it is not cleared or overshadowed by the variable having a same name? Use "WHICH F1" command to make a diagnostic.
>
======
But... can you explain what i should do to solve this probem conctretely?
what does it mean to 'Use "WHICH F1" command to make a diagnostic'?

 0

>
> That error happens if for some reason Matlab see F1 as (array) VARIABLE and not as FUNCTION. Are you sure you declare the function F1 properly, and it is not cleared or overshadowed by the variable having a same name? Use "WHICH F1" command to make a diagnostic.
>
======
But... can you explain what i should do to solve this probem conctretely?
what does it mean to 'Use "WHICH F1" command to make a diagnostic'?

 0

"JKA tom" <everjkahn@hanmail.net> wrote in message <hqjjqo$f5i$1@fred.mathworks.com>...
> >
> > That error happens if for some reason Matlab see F1 as (array) VARIABLE and not as FUNCTION. Are you sure you declare the function F1 properly, and it is not cleared or overshadowed by the variable having a same name? Use "WHICH F1" command to make a diagnostic.
> >
> ======
> But... can you explain what i should do to solve this probem conctretely?
> what does it mean to 'Use "WHICH F1" command to make a diagnostic'?

help which

The following illustrate with SUM instead of F1.

>> sum(0)

ans =

0

>> which sum
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\datafun\@uint8\sum)  % uint8 method
>> sum=[1 2 3]

sum =

1     2     3

>> which sum
sum is a variable.
>> sum(0)
??? Subscript indices must either be real positive integers or logicals.

% Bruno

 0

Wow~GOT IT
Thanks a lot~

 0

6 Replies
290 Views

Similiar Articles:

7/24/2012 5:24:25 PM