필터 지우기
필터 지우기

Symbolic manipulation and integration / not enough input argument

조회 수: 1 (최근 30일)
Mauro De Francesco
Mauro De Francesco 2018년 10월 9일
댓글: Stephan 2018년 10월 10일
Hello, I have two symbolic functions that i want to integrate. I have converted with matlabFunction the equations into a file here reported:
function DY = Pendulum(theta,w,l)
%PENDULUM
% DY = PENDULUM(THETA,W,L)
% This function was generated by the Symbolic Math Toolbox version 8.2.
% 09-Oct-2018 12:30:20
DY = [w;(sin(theta).*(-9.81e2./1.0e2))./l];
Where the variables are theta and w and l is a constant. Now I want to integrate like this:
X0 = [90*pi/180 ; 1.2];
[tout,yout] = ode45(@Pendulum, [0 5], X0, 2 );
and i get the error Not enough input arguments.
Can someone please explain what is the problem?

답변 (3개)

madhan ravi
madhan ravi 2018년 10월 9일
편집: madhan ravi 2018년 10월 9일
X0 = [90*pi/180 ; 1.2];
[tout,yout] = ode45(@Pendulum, [0 5], X0)
plot(tout,yout(:,1),'r' )
hold on
plot(tout,yout(:,2),'b')
function DY = Pendulum(theta,w,l)
%PENDULUM
w=1; % error was here because w and l were not defined , I gave w and l as an example change it according to your values
l=2;
% DY = PENDULUM(THETA,W,L)
% This function was generated by the Symbolic Math Toolbox version 8.2.
% 09-Oct-2018 12:30:20
DY = [w;(sin(theta).*(-9.81e2./1.0e2))./l];
end
  댓글 수: 8
Stephan
Stephan 2018년 10월 10일
편집: Stephan 2018년 10월 10일
@Madhan: The ode of pendulum is a second order ode. The system of odes given here is the converted first order sytem which is equivalent to the equation of pendulum i think.
madhan ravi
madhan ravi 2018년 10월 10일
@stephen maybe but I’m stuck at this point .

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


Walter Roberson
Walter Roberson 2018년 10월 9일
ode45(@(theta, w) Pendulum(theta, w, SomeValueForL)
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 10월 9일
You are copying all of w into the output and another value as well. w is length 2 so the result is length 3. You should probably be using w(2) instead of w in constructing the output
Walter Roberson
Walter Roberson 2018년 10월 9일
w = sym('w', [2 1]);
syms theta L
om_d = .... something involving w, theta, and L
Y = [w(1) ; om_d];
matlabFunction(Y, 'File', 'Pendulum', 'Vars', {theta w L},...
'Outputs',{'DY'});
X0 = [90*pi/180 ; 1.2];
L = 2;
[tout,yout] = ode45(@(theta, w) Pendulum(theta, w, L) , [0 5], X0);
... When I am typing on my phone in the middle of the night, I sometimes only give the outline of the change, as editing by poking with one figure is not all that productive.

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


Stephan
Stephan 2018년 10월 9일
편집: Stephan 2018년 10월 10일
Edit
Here is another approach, inspired by Walters answer:
syms phi(t) g l
eqn = diff(phi,t,2) + g/l * sin(phi) == 0;
eqn = odeToVectorField(eqn);
Pendulum = matlabFunction(eqn, 'File', 'Pendulum','vars',{'t','Y','g','l'},'Outputs',{'DY'});
X0 = [90*pi/180, 1.2];
l = 2;
g = 9.81;
[tout,yout] = ode45(@(t,Y)Pendulum(t,Y,g,l), [0 5], X0);
plot(tout,yout(:,1),'r',tout,yout(:,2),'b')
With the resulting Pendulum.m file:
function DY = Pendulum(t,Y,g,l)
%PENDULUM
% DY = PENDULUM(T,Y,G,L)
% This function was generated by the Symbolic Math Toolbox version 8.2.
% 10-Oct-2018 08:21:21
DY = [Y(2);-(g.*sin(Y(1)))./l];
Theta and w are Y(1) and Y(2) here.
Best regards
Stephan
  댓글 수: 3
Stephan
Stephan 2018년 10월 9일
Then you should use the answer from Walter.
Stephan
Stephan 2018년 10월 10일
See my edited answer

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by