Too many input arguments

조회 수: 10 (최근 30일)
Brian Batson
Brian Batson 2013년 1월 10일
댓글: Walter Roberson 2016년 5월 24일
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
  댓글 수: 5
SHIJINA P P
SHIJINA P P 2016년 5월 24일
line 15
Walter Roberson
Walter Roberson 2016년 5월 24일
Line 15 is a comment.

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

답변 (2개)

Walter Roberson
Walter Roberson 2013년 1월 11일
Change your line
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
Leah 2013년 1월 10일
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
Brian Batson
Brian Batson 2013년 1월 10일
I am specifying the model parameters, pasting them into a model, and setting an approximation structure. See below. I think it has to be in the func that I defined above, but it doesn't notify me where the error is. I believe it might have to do something with the size of out2 under the g flag...
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
Leah
Leah 2013년 1월 10일
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

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by