MATLAB error: too many input arguments
조회 수: 1 (최근 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
댓글 수: 0
채택된 답변
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);
댓글 수: 0
추가 답변 (1개)
Enrico Picari
2013년 2월 10일
댓글 수: 4
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
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 Center 및 File Exchange에서 Simscape Multibody에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!