Mass on Slope Example

From Control Engineering
Jump to navigation Jump to search

Basic Differential Model

Matlab Code Example

% time scale
t=0:0.001:3;   
% Initial Conditions
x_0  = 0;
dx_0 = 0;
% Simulate
[t,x]=ode45( @fun, t, [x_0 dx_0]);
%
% Plot Data
figure(1)
plot(t,x(:,1));
xlabel('time(s)'); ylabel('displacement(m)');
figure(2)
plot(t,x(:,2));
xlabel('time(s)'); ylabel('velocity(m/s)');
% 
% Define differential function
function dx=fun(t, x)
    % Define constants
    F_sc = 20;
    B_v = 10;
    m = 5;
    theta = 0.5;
    % Define Differential equations
    dx_1 = x(2);
    dx_2 = (-9.81*sin(theta)*m - F_sc*tanh(1000*x(2)) - B_v*x(2))/m;
    dx=[dx_1; dx_2];
end