MrPitivier
MrPitivier

Reputation: 71

From ODE45 take Angular acceleration MATLAB

I'm solving the eqaution motion and I need numerical integration, so I decided to use ode45 in Matlab. I found the displacement and the velocity, now I need to find the Angular acceleration and make plot with time.

There's my code and function:

Code:

global r b m2 m3 m4 g I M

% Quantities
r=0.2;
b=0.1;
m2=1;
m3=0.2;
m4=2;
g=9.81;
tspan=0:0.01:2;

% Calculation
I=(m2*r^2)/3
M0=m2*g*b+g*r*(m3+m4)
M=1.2*M0

% Runge- Kutta
[t,x]=ode45(@funkce,tspan,[0 0]);

% Plotting 
figure(1);
plot(t,x(:,2));
grid;

figure(2);
plot(t,x(:,1));
grid;

Function:

function v=funkce(t,x);

global r b m2 m3 m4 g I M

% Method
v(1,1)= (x(1)^2*(m4*r^2*cos(x(2))*sin(x(2)))+M-cos(x(2))*m2*g*b+(m3+m4)*g*r)/(I+m3*r^2+m4*r^2*cos(x(2))^2);
v(2,1)= x(1);

Upvotes: 0

Views: 1673

Answers (1)

am304
am304

Reputation: 13876

Maybe, I'm missing something but if you have the displacement and velocity, the only thing you need to do to get the acceleration is to differentiate the velocity:

% Assuming x(:,1) is the velocity, haven't checked your equations
accel = zeros(size(x(:,1)));
accel(2:end) = diff(x(:,1))./diff(t);

However, when I tried to run your code on Octave, ode45 wasn't able to solve the equations. The plots looked like this:

enter image description here

Are you able to obtain meaningful results for the displacement and velocity in MATLAB? If not, I suggest you check your equations and make sure you get sensible results before trying to derive the acceleration.

Upvotes: 1

Related Questions