Driven Damped Pendulum Axes Question

8 次查看(过去 30 天)
Hello, I am quite new to MATLab, this is my very first program, which is also a uni assignment. This is my program thus far:
m=2;
l=5;
g=9.81;
c=0.5;
theta=45;
theta_dot=5;
t=0;
dt=(0.1/theta_dot);
while t<50
theta_dotdot=-(g/l)*sin(theta) - (c/m*l^2)*theta_dot; %motion eqn
theta=theta+dt*theta_dot;
theta_dot=theta_dot+dt*theta_dotdot;
figure(1);
axis([0 0 -2*pi -2*pi]);
hold on;
plot(theta_dotdot, theta);
t=t+dt;
end
What I have done so far (the code above explained): 1.Giving some values (the first part of the code). 2.The equation of motion (%motion eqn). 3.Theta and Theta_dot increasing in value (recommended method/code I was given in the assignment). 4. Figure - doesn't work, and I am not quite sure how it should work. 5. Plot - no reason for it not to work, I assume it doesn't plot anything because of the figure error above. 6. t increasing. 7. Everything above is looped, with t=t+dt What I need to do: Firstly, I need it to give me a figure of the pendulum positions (don't know how to explain this better)- the figure part of the code Secondly, I need it to plot theta_dotdot, theta. I think I got this part right, but the program does not run that part yet, im assuming because of the errors in the figure part.
There are the erros im getting:
>> run Untitled2
Error using set
Bad property value found.
Object Name: axes
Property Name: 'XLim'
Values must be increasing and non-NaN.
Error in axis>LocSetLimits (line 201)
set(ax,...
Error in axis (line 93)
LocSetLimits(ax(j),cur_arg);
Error in Untitled2 (line 17)
axis([0 0 -2*pi -2*pi]);
Error in run (line 63)
evalin('caller', [script ';']);
>>
If an answer can not be provided, I could really use some help on the errors, why am I getting them, what do they mean.
  2 个评论
Star Strider
Star Strider 2015-2-16
See the documentation for ode45. I would use it rather than attempt to integrate your ODE with your own integration routine, unless for some reason you are not allowed to.
Calin Pastean
Calin Pastean 2015-2-16
@StarStrider: I am pretty sure they are not expecting anything too complex, since it is a first year course, first assignment. It just seems to me that there is no link between my equations and the figure 'generator'. if I run the program I also get Figure(1) without anything on it.

请先登录,再进行评论。

采纳的回答

Youssef  Khmou
Youssef Khmou 2015-2-16
编辑:Youssef Khmou 2015-2-16
The implementation is acceptable, the first remark is that visualization commands of results should be outside the loop, otherwise you obtain N plots where N is the number of iterations. While loop in this case can be changed into for loop but not necessary, the following version is working , but the physical interpretation still needs correction of the code, try to adjust it :
m=2;
l=5;
g=9.81;
c=0.5;
thet=45;
dtheta=5;
t=0;
dt=(0.1/dtheta);
cc=1;
for t=1:dt:50
d2theta(cc)=-(g/l)*sin(thet) - (c/m*l^2)*dtheta; %motion eqn
theta(cc)=thet+dt*dtheta;
dtheta=dtheta+dt*d2theta(cc);
cc=cc+1;
end
figure(1);
% axis([0 0 -2*pi -2*pi]);
% hold on;
plot(d2theta, theta);

更多回答(1 个)

MKG
MKG 2015-2-17
Hello, try the following code for your x limits: axis([-2*pi 0 -2*pi 0])
Regards, Martin

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by