# Too many input arguments

68 views (last 30 days)
Brian Batson on 10 Jan 2013
Commented: Walter Roberson on 24 May 2016
Hi,
I am still pretty new to Matlab, but am receiving a "too many input arguments" error. The code below basically is a setup to solve a Bellman equation using dpsolve (Fackler and Miranda's CompEcon toolbox). I essentially have 2 control/action variables and 1 state variable. The code first sets the bounds of the continuous control variable (bounded between 0 and the size of the state variable), then runs through the value function by means of first and second order derivatives, then runs through the state equation with first derivatives. I'm just not sure why this error is occurring. Any help would be appreciated. Thanks in advance, Brian.
function [out1,out2,out3] = func(flag,s,x,e,alpha,beta);
n = size(s,1); %defines space and returnsnumber of rows, s is a vector
ds = 1; %defines number of continuous state variables
dx = 2; %defines number of continuous action variables
switch flag
case 'b'
out1 = zeros(size(s));
%outputs zeros for the vector s, lower bound for continuous control variables x
out2 = s;
%outputs the values of s, upper bound for continuous control variables x
case 'f'
out2 = zeros(n,dx);
%outputs zeros for the n by dx matrix, n must be a scalar
out3 = zeros(n,dx,dx);
%outputs zeros for the dx-th page, 3 dimensions to include second derivatives
out1 = x(:,1).^alpha+x(:,2).^beta;
%value function
out2(:,1) = alpha*x(:,1).^(alpha-1);
%first derivative of value function wrt first control variable
out2(:,2) = beta*x(:,2).^(beta-1);
%first derivative of value fucntion wrt second control variable
out3(:,1,1) = alpha*(alpha-1)*x(:,1).^(alpha-2);
%second derivative of value function wrt first control variable
out3(:,2,2) = beta*(beta-1)*x(:,2).^(beta-2);
%second derivative of value function wrt second control variable
case 'g'
out2 = zeros(n,ds,dx);
%outputs zeros for the pages of the first derivatives (adding 3rd dimension)
out3 = zeros(n,ds,dx,dx);
%outputs zeros for the pages of the second derivatives (adding 4th dimension)
out1 = s-x(:,1)-x(:,2);
%level of state equation
out2(:,1,2) = -ones(n,1);
out2(:,2,2) = -ones(n,1);
end
Walter Roberson on 24 May 2016
Line 15 is a comment.

Walter Roberson on 11 Jan 2013
function [out1,out2,out3] = func(flag,s,x,e,alpha,beta);
to
function [out1,out2,out3] = func(flag, s, x, e, alpha, beta, varargin);
and save that, and then put a breakpoint at the first line of "func". When it stops, examine size(varargin) to see how many parameters were actually passed.

Leah on 10 Jan 2013
You must be inputting too many arguments when you call the func. Make sure you are only inputting six arguments. What are you executing in the command window when you call your function? Something like this? You could always comment out the first line and evaluate it as a script and define
flag=1;
s=[0 5 4];
x= 2;
%etc...
##### 2 CommentsShowHide 1 older comment
Leah on 10 Jan 2013
Place a try catch around the script above and you will be able to see where the error is occurring in the variable ex. Matlab does notify you of where the error is occurring on your command window. The error has to be occurring inside dpsolve since that is where func is used.
try
alpha = 0.4;
beta = 0.2;
delta = 0.05;
model.func = @func; %calling the formula into the model
model.params = {alpha beta}; %calling the parameters into the model
model.discount = delta; %telling the program that delta is the disc. rate
model.ds = 1; %telling the model that there is only 1 state variable
model.dx = 2; %telling the model that there are 2 control variables
n = 60; %approximation structure
smin = 0; %state variable cannot go below zero
smax = 500; %state variable cannot exceed 500
basis = fundefn('spli',n,smin,smax); %this is a func from the book I mentioned
[s,x,resid] = dpsolve(model,basis); %solves the Bellman using the model
catch ex
ex.stack
end