Error using==> nargin

조회 수: 11 (최근 30일)
Raphel
Raphel 2011년 10월 31일
편집: pavitra ramdas 2015년 2월 12일
Hi,
I am a new user to mathlab, and trying to solve 11 simultaneous 1st order differential equation:
Here is the M-file :
funtion dxdt=anu(t,x)
%x(1)=xA, x(2)=xB, x(3)=xC, x(4)=xD, x(5)=xE, x(6)=xF, x(7)=xG, x(8)=xH,
%x(9)=xI, x(10)=xJ, x(11)=xK
global kg ka kb kc kd Z
dxdt=[-kg/Z*(x(2)+x(4)+x(7)+x(10)+x(11)); 1/Z*(kg*x(1)-ka*x(2)); 1/Z*ka*x(2); 1/Z*(kg*x(1)-kb*x(4)); 1/Z*(kb*x(4)-2*kd*x(5)); 1/Z*kd*(x(5)+x(8));1/Z*(kg*x(1)-kc*x(7)); 1/Z*(kc*x(7)-2*kd*x(8)); 1/Z*kd*(x(5)+x(8)); 1/Z*kg*x(1); 1/Z*kg*x(1)];
This is the call function:
>> clf
>> global kg ka kb kc kd Z
>> kg=0.03118;
>> ka=0.0042;
>> kb=0.000083;
>> kc=0;
>> kd=0.00025;
>> Z=4.056*10^-4;
>> tspan=[0:10:240];
>> x0=[1 0 0 0 0 0 0 0 0 0 0];
>> [t,x]=ode45('anu',tspan,x0);
Here is the error i got:
??? Error using ==> nargin
anu is a script.
Error in ==> funfun\private\odearguments at 80
if (nargin(ode) == 2)
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Somebody please help, i am new to mathlab so please simply.. Thanks

답변 (6개)

Walter Roberson
Walter Roberson 2011년 10월 31일
Your function anu starts with the word
funtion
which is missing the 'c'.
  댓글 수: 1
Jan
Jan 2011년 10월 31일
After eating a soup with noodles shaped like characters ("Buchstabennudeln"), a friend of mine told me: "Jan, da liegt ein C auf dem Tisch" (there lies a C on the table). It was distusting, because I understood: "da liegt ein Zeh auf dem Tisch" (the lies a toe on the table).
I wish you and all readers a scary halloween.

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


Walter Roberson
Walter Roberson 2011년 10월 31일
Earlier in your path, you must have another anu.m file that is a script (no "function" line)
Try
which -all anu
and compare that to the anu that you are expecting to be invoked.
Note: if the anu function that you show above is stored in a file other than anu.m then MATLAB will not be able to find the right file when you pass 'anu' as a quoted string to ode45: passing as a quoted string always forces MATLAB to feval() the name in the base workspace. Using function handles such as @anu is more likely to work in such a situation.

Raphel
Raphel 2011년 10월 31일
Thanks for the quick response, anu was new m-file, i didnt have it earlier. Its stored in anu.m. can you explain how to use @anu??
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 10월 31일
Note: if there is *any* executable line in anu.m before the "function" line, then the file would be considered a script rather than a function. You need it to be a function.
Dennis
Dennis 2011년 10월 31일
Walter i got the error after following up on your recomendations:
Warning: feval on script names will not work, or may work differently,
in a future version of MATLAB. To make your code insensitive to any change
and to suppress this warning message:
- Either change the script to a function.
- Or use eval instead of feval.
The script file in question is anu.
> In funfun\private\odearguments at 110
In ode45 at 173
??? Attempt to execute SCRIPT anu as a function.
Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...

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


Dennis
Dennis 2011년 10월 31일
Hi Walter, When did: [t,x]=ode45(@anu,tspan,x0); i got error: Warning: feval on script names will not work, or may work differently, in a future version of MATLAB. To make your code insensitive to any change and to suppress this warning message: - Either change the script to a function. - Or use eval instead of feval. The script file in question is anu. > In funfun\private\odearguments at 110 In ode45 at 173 ??? Attempt to execute SCRIPT anu as a function.
Error in ==> funfun\private\odearguments at 110 f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ... Please help!

Dennis
Dennis 2011년 10월 31일
Walter, Thank you soo much.. Dennis K
  댓글 수: 1
pavitra ramdas
pavitra ramdas 2015년 2월 12일
편집: pavitra ramdas 2015년 2월 12일
Did it work? I have the same problem. I executed it as a function and I am still getting the same error

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


pavitra ramdas
pavitra ramdas 2015년 2월 12일
편집: pavitra ramdas 2015년 2월 12일
I have the same problem. I executed it as a function and I am still getting the same error

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by