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 Untitled2Error using setBad property value found.Object Name: axesProperty 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.
Best Answer