MATLAB error: too many input arguments

6 visualizaciones (últimos 30 días)
Enrico Picari
Enrico Picari el 10 de Feb. de 2013
Comentada: Walter Roberson el 9 de Oct. de 2017
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

Respuesta aceptada

the cyclist
the cyclist el 10 de Feb. de 2013
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);

Más respuestas (1)

Enrico Picari
Enrico Picari el 10 de Feb. de 2013
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 comentarios
dinesh reddy
dinesh reddy el 9 de Oct. de 2017
Editada: Walter Roberson el 9 de Oct. de 2017
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 el 9 de Oct. de 2017
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Simscape Multibody en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by