MATLAB error: too many input arguments

9 次查看(过去 30 天)
Hi, I'm trying to solve the variable length pendulum equation with ODE45
here are the codes:
-------------------------
%Pendulum of variable length: T is the period, th0 the initial conditions
%for the angulus and angular velocity, eta is the length parameter and g
%is the gravitational acceleration
%for the length law l(t) see 'el.m'
%for the motion equations see 'eq_varpend.m'
%usage: [t,th] = varpend
function [t,th] = varpend()
entries={
'T',...
'th0',...
'eta',...
'g',...
};
default={
'30*pi',...
'pi/6',...
'1.0',...
'9.8',...
};
setup = inputdlg(entries,'Variable length pendulum',1,default,'on');
T=str2num(setup{1});
th0=[str2num(setup{2}),0];
eta=str2num(setup{3});
g=str2num(setup{4});
opt=odeset('Abs',1e-10,'Rel',1e-10);
[t,th]=ode45('eq_varpend', [0,T], th0, opt, eta, g);
plot(t,th(:,1));
grid on
xlim([0 T])
title('Pendulum trajectory');
figure(2)
plot(th(:,1), th(:,2));
grid on
axis equal
title('Phase space');
------
%motion equation fot the v.l. pendulum
function dtheta = eq_varpend(t,th,eta,g)
[q,qdot] = el(t,eta);
dtheta = [ th(2) ; -g*sin(th(1))./q-2*th(2).*qdot./q; ];
------
%length law for the v.l. pendulum
function [q,qdot] = el(t,eta)
q = 1+eta*t;
qdot = eta;
------
When I type [t,th] = varpend I get the following error message:
Error using eq_varpend
Too many input arguments.
Can anyone help me? Thanks

采纳的回答

the cyclist
the cyclist 2013-2-10
I replaced your first argument to ode45 with the function handle @eq_varpend, and your code worked fine for me:
[t,th]=ode45(@eq_varpend, [0,T], th0, opt, eta, g);

更多回答(1 个)

Enrico Picari
Enrico Picari 2013-2-10
It works for me too. Quite strange, in other codes the apostrophes did't return any error...
Anyway, great great thanks! It was driving me crazy!
  4 个评论
dinesh reddy
dinesh reddy 2017-10-9
编辑:Walter Roberson 2017-10-9
function [swav]=s_wav(x)
l=1;
x=x-l/6;
a=0.25;
b=15;
n=100;
s1=(a/(2*b))*(2-b);
s2=0;
for i = 1:n
harm3=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
s2=s2+harm3;
end
swav=-1*(s1+s2);
%%I generated the S wave of ecg signal by using the above code%%
%%By using below code i am running it and i was struck with an error called too many input arguments can any one help me%%
x=0.01:0.01:2;
default=input('press 2:\n');
rate=input('\n\nenter the heart beat rate :');
li=30/rate;
fprintf('\n\ns wave specifications\n');
a_swav=input('amplitude = ');
d_swav=input('duration = ');
swav=s_wav(x,a_swav,d_swav,t_swav,li);
Walter Roberson
Walter Roberson 2017-10-9
You define s_wav as taking 1 single parameter. Your call s_wav(x,a_swav,d_swav,t_swav,li) tries to provide 5 parameters to s_wav . Your exising s_wav code does not even appear to have any place it could use those extra parameters.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simscape Multibody 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by