0% found this document useful (0 votes)
3 views

Modelling Assignment 2-1

The document presents a simulation of a nonlinear system involving a cart and a pendulum, using parameters such as mass and damping coefficients. It compares the responses of linear and nonlinear models, highlighting that they align at small angles and low velocities but diverge under larger forces or angles. The analysis concludes that while the linear model is useful near equilibrium, the nonlinear model is essential for understanding the system's dynamics in extreme conditions.

Uploaded by

youssefsaied472
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Modelling Assignment 2-1

The document presents a simulation of a nonlinear system involving a cart and a pendulum, using parameters such as mass and damping coefficients. It compares the responses of linear and nonlinear models, highlighting that they align at small angles and low velocities but diverge under larger forces or angles. The analysis concludes that while the linear model is useful near equilibrium, the nonlinear model is essential for understanding the system's dynamics in extreme conditions.

Uploaded by

youssefsaied472
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment 2

Noureldin Walid
13003398
T-16
m = 0.32;
M = 0.7;
bx = 15;
btheta = 0.0015;
L = 0.44;
g = 9.81;
function dx = nonlinear_system(t, x, u, params)
m = params.m;
M = params.M;
bx = params.bx;
btheta = params.btheta;
L = params.L;
g = params.g;
dx = zeros(4,1);
xc = x(1);
dxc = x(2);
theta = x(3);
dtheta = x(4);
% Nonlinear equations
ddxc = (1/(m + M)) * (u(t) - bx*dxc + 0.5*M*L*dtheta^2*sin(theta));
ddtheta = (1/((1/3)*M*L^2)) * (-0.5*M*L*g*sin(theta) - btheta*dtheta);
% State derivatives
dx(1) = dxc;
dx(2) = ddxc;
dx(3) = dtheta;
dx(4) = ddtheta;
end
params = struct('m',0.32,'M',0.7,'bx',15,'btheta',0.0015,'L',0.44,'g',9.81);
u = @(t) (t < 0.5) * 10;
tspan = [0 10];
x0 = [0; 0; 0; 0];
[t_nl, x_nl] = ode45(@(t, x) nonlinear_system(t, x, u, params), tspan, x0);
m = 0.32;
M = 0.7;
bx = 15;
btheta = 0.0015;
L = 0.44;
g = 9.81;
A = [0 1 0 0;
0 -bx/(m+M) 0 0;
0 0 0 1;
0 0 -(0.5*M*g*L)/((1/3)*M*L^2) -btheta/((1/3)*M*L^2)];
B = [0;
1/(m+M);
0;
0];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
sys = ss(A, B, C, D);
t = linspace(0, 10, 1000);
u_signal = (t < 0.5) * 10;
[y_lin, t_lin, x_lin] = lsim(sys, u_signal, t, [0 0 0 0]);
figure;
subplot(2,1,1);
plot(t_nl, x_nl(:,1), 'r', 'LineWidth' , 1.5);
hold on;
plot(t_lin, y_lin(:,1), 'b--', 'LineWidth' , 1.5);
xlabel( 'Time (s)' ); ylabel( 'Cart Position x_c (m)' );
legend( 'Nonlinear' , 'Linear' ); title( 'Cart Position' );
subplot(2,1,2);
plot(t_nl, x_nl(:,3), 'r', 'LineWidth' , 1.5); hold on;
plot(t_lin, y_lin(:,2), 'b--', 'LineWidth' , 1.5);
xlabel( 'Time (s)' ); ylabel( 'Pendulum Angle \theta (rad)' );
legend( 'Nonlinear' , 'Linear' ); title( 'Pendulum Angle' );
Commenting on the results:
The linear and nonlinear systems show similar responses when the pendulum operates
at small angles and low velocities. This is because the linear model simplifies the
equations by neglecting nonlinear terms, such as θ˙2sin(θ)\dot{\theta}^2 \sin(\theta)
θ˙2sin(θ), which are present in the full nonlinear model. As the input force increases or
the pendulum deviates further from the vertical position, the nonlinear effects become
more noticeable. Therefore, while the linear model is effective for analyzing system
behavior near the equilibrium point (θ=0\theta = 0θ=0), the nonlinear model is
necessary to accurately capture the system's dynamics under more extreme
conditions.

You might also like