errors when running file

조회 수: 8 (최근 30일)
garrett schander
garrett schander 2015년 8월 12일
댓글: Walter Roberson 2015년 8월 12일
while try to run this function i run into 4 codes and i dont know how to fix them
function hh
tspan=[0 25];
y0=[0.1;0;0.2;0];
options=odeset('mass','M(t,y)');
[t,y]=ode113(@z,tspan,y0,options);
subplot(2,1,1)
plot(t,y(:,1))
grid
xlabel('Time')
ylabel('Theta1')
subplot(2,1,2)
plot(t,y(:,3))
grid
xlabel('Time')
ylabel('Theta2')
function varargout=z(t,y,flag)
switch flag
case ''
varargout{1}= da_p(t,y);
case 'mass'
varargout{1}= dc_m(t,y);
otherwise
error(['unknown flag ''' flag '''.']);
end
function m= dc_m(t,y)
M1=1;
M2=1;
g=9.81;
l1=1;
l2=1;
a=[1,0,0,0];
b=[0,(M1+M2)*l1,0,M2*l2*cos(y(3)-y(1))];
c=[0,0,1,0];
d=[0,M2*l1*cos(y(3)-y(1)),0,M2*l2];
m=[a;b;c;d];
function p= da_p(t,y)
M1=1;
M2=1;
g=9.81;
l1=1;
l2=1;
a=M2*9.81;
b=M1*9.81;
p=zeros(4,1);
p(1)=y(2);
p(2)=-(b+a)*sin(y(1))+M2*l2*(y(4)^2)*sin(y(3)-y(1));
p(3)=y(4);
p(4)=-a*sin(y(3))-M2*l1*(y(2)^2)*sin(y(3)-y(1));
codes
Error using hh>z (line 18)
Not enough input arguments.
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode113 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,
...
Error in hh (line 5)
[t,y]=ode113(@z,tspan,y0,options);
this is the answer i am looking to reach. i can get it when i split files and get rid of the function file hh and make it a script file
%

답변 (1개)

Hikaru
Hikaru 2015년 8월 12일
The function hh doesn't have input. I think MATLAB expect it to have at least one input. You need to change the first line into something like this:
function hh(tspan,y0)
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 8월 12일
No this has nothing to do with input to hh. The function z is the one that does not have enough inputs. The creation of the mass matrix has been coded in a form that was replaced as of R12 in the year 2000.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by