MATLAB Answers

Too many Input arguments

3 views (last 30 days)
I am trying to optimize the attached problem, but I always receive these errors
Error using objfuntest>@(X)ODEtest(X,g0,Isp,thrust)
Too many input arguments.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in objfuntest (line 12)
[t,x]=ode45(@(X)ODEtest(X,g0,Isp,thrust),tSpan,initial,options);%solve equations for
Optimization
Error in maintest>@(X)objfuntest
Error in fmincon (line 546)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in maintest (line 15)
mfopti=fmincon(myObjective,X0,A,b,Aeq,beq,lb,ub,nonlcon)
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
And I don't get it, because if I don't pass the parameters to my function I get the same error. But that would mean that I have to clear also the input X, so that I don't have any input, which makes no sense to me. Can anyone see my error of reasoning?
Thanks in advance

Accepted Answer

Star Strider
Star Strider on 5 Jan 2019
There are several problems with your code. The error you posted was due to requirement that ODE arguments to the differential equation solvers must allow for in independent variable (usually ‘t’) as the first argument. Correcting those, and adding the ‘alpha’ calculation to ‘objfuntest’ got this much to work:
function dX=ODEtest(t,X,g0,Isp,thrust)
%constants
ceff=Isp*g0;%[m/s]
propflow=thrust/ceff;%[kg/s]
%differential equations
alpha=atan(X(3)/X(1));
dX(1)=X(2);
dX(2)=(thrust*cos(alpha))/X(5);
dX(3)=X(4);
dX(4)=(thrust*sin(alpha))/X(5);
dX(5)=-propflow;
%Definition of dX
dX=[dX(1);dX(2);dX(3);dX(4);dX(5)];
end
function mp=objfuntest(X)
%constants
thrust=933910;%[N]
g0=9.81;%[m/s^2]
Isp=390;%[s]
ceff=Isp*g0;%[m/s]
propflow=thrust/ceff;%[kg/s]
%solve ODEs
tSpan=[.01 30];
initial=[.01 .01 .01 .01 68e3];%initial gues for x(0),ax(0),y(0),ay(0),m(0)
options=odeset('RelTol',1,'AbsTol',1);
[t,x]=ode45(@(t,X)ODEtest(t,X,g0,Isp,thrust),tSpan,initial,options);%solve equations for Optimization
%Exert information
x1=x(:,1);%first column of the x vector=Position in x direction
x2=x(:,2);%second column of the x vector=Acceleration in x direction
y1=x(:,3);%third column of the x vector=Position in y direction
y2=x(:,4);%fourth column of the x vector=Acceleration in y direction
m=x(:,5);%fifth column of the x vector= Mass
%objective function
alpha=atan(X(3)/X(1));
mp=-propflow*sqrt(2*X(1)*X(5)/(thrust*cos(alpha)));
end
%constraint function
function [c,ceq]=constrainttest(X)
tSpan=[.01 30];
initial=[.01 .01 .01 .01 68e3];%initial gues for x(0),ax(0),y(0),ay(0),m(0)
g0=9.81;
Isp=390;
thrust=933910;
options=odeset('RelTol',1,'AbsTol',1);
[t,x]=ode45(@(t,X)ODEtest(t,X,g0,Isp,thrust),tSpan,initial,options);%solve equations for Optimization
%Exert information
x1=x(:,1);%first column of the x vector=Position in x direction
y1=x(:,3);%third column of the x vector=Position in y direction
if y1>=5e5
c=7e5-x1;%sobald die y Koordinate größer gleich 5e5 ist, muss der x Wert größer 7e5 sein
ceq=[x1-8e5;y1-8e5];
else
c=[];
ceq=[x1-8e5;y1-8e5];
end
end
That eliminates the original errors, and your code now runs. Your ‘maintest.m’ file is unchanged, so I did not post it here.
However the result when I ran it is:
Converged to an infeasible point.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance but constraints are not
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
mfopti =
999.9979e+003
4.8819e+006
150.6695e+003
4.8819e+006
69.9999e+003
I leave that to you to resolve.
  6 Comments
Star Strider
Star Strider on 6 Jan 2019
As always, my pleasure!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!