Error using==> nargin

7 views (last 30 days)
Raphel
Raphel on 31 Oct 2011
Edited: pavitra ramdas on 12 Feb 2015
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

Answers (6)

Walter Roberson
Walter Roberson on 31 Oct 2011
Your function anu starts with the word
funtion
which is missing the 'c'.
  1 Comment
Jan
Jan on 31 Oct 2011
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.

Sign in to comment.


Walter Roberson
Walter Roberson on 31 Oct 2011
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 on 31 Oct 2011
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 Comments
Walter Roberson
Walter Roberson on 31 Oct 2011
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 on 31 Oct 2011
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, ...

Sign in to comment.


Dennis
Dennis on 31 Oct 2011
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 on 31 Oct 2011
Walter, Thank you soo much.. Dennis K
  1 Comment
pavitra ramdas
pavitra ramdas on 12 Feb 2015
Edited: pavitra ramdas on 12 Feb 2015
Did it work? I have the same problem. I executed it as a function and I am still getting the same error

Sign in to comment.


pavitra ramdas
pavitra ramdas on 12 Feb 2015
Edited: pavitra ramdas on 12 Feb 2015
I have the same problem. I executed it as a function and I am still getting the same error

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!