I'm trying to solve a 2nd order differential equation, using the Runga Kutta's ode45 function in Matlab. It's for a bachelor project, where I'm trying to simulate the behavior of a spherical robot, with a pendulum swinging inside to cause it to roll.
So far it's limited to only roll in one direction and is tested where the pendulum is started at an angle of -pi/4 and should in this case just cause and oscillation, where the angle is measured in the equation.
The problem is, when I plot the graph, I always get some odd linear component. Tried the program on another computer, where it did not show up, so I'm kinda lost here. I also tried to simulate the pendulum itself, where the graph is as shown:
The sine with the greater amplitude is the displacement of the angle.
The program is as follows:
function xdot = pendulum(t,y); xdot = zeros(2,1); g = 9.82; L = 1; xdot(1) = y(2); xdot(2) = -(g*sin(y(1))/L; x0 = [-pi/4 0 ]; [T Y] = ode45(@pendulum, [0 20], x0); plot([T Y])
Hope that someone know how to correct this error, since it's making it nearly impossible to get an acceptable simulation, when I'm adding the sphere in the equations of motion.