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
Reply JKA 4/20/2010 4:49:04 AM

"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
Reply Bruno 4/20/2010 6:27:20 AM


> 
> 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.
>
======
Thanks for you reply.
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
Reply JKA 4/20/2010 7:04:04 AM

> 
> 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.
>
======
Thanks for you reply.
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
Reply JKA 4/20/2010 7:06:04 AM

> 
> 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.
>
======
Thanks for you reply.
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
Reply JKA 4/20/2010 7:07:04 AM

"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.
> >
> ======
> Thanks for you reply.
> 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
Reply Bruno 4/20/2010 7:27:04 AM

Wow~GOT IT
Thanks a lot~
0
Reply JKA 4/20/2010 10:24:03 AM

6 Replies
290 Views

(page loaded in 0.019 seconds)

Similiar Articles:













7/24/2012 5:24:25 PM


Reply: