Modeling
Modeling
STUDENT ID:2106203
6.5 problem
A=[0 1; -34 -2];
B=[0;2.5];
C=[1 0];
D=0;
sys=ss(A,B,C,D);
time=0:0.001:6;
u=0.6*ones(size(time));
X0=[2; -1.5];
[y,time]=lsim(sys,u,time,X0);
plot(time,y);
6.1 Problem
J = 0.5;
omega_0 = 40;
b = 0.06;
t_start = 0;
t_end = 10;
dt = 0.01;
theta_0 = 0;
omega = omega_0;
time = t_start:dt:t_end;
theta = zeros(size(time));
omega_vals = zeros(size(time));
energy_dissipated = zeros(size(time));
for i = 1:numel(time)
torque_friction = -b * omega;
alpha = torque_friction / J;
theta(i) = theta_0;
omega_vals(i) = omega;
end
subplot(2, 1, 1);
plot(time, theta);
xlabel('Time (s)');
subplot(2, 1, 2);
plot(time, omega_vals);
xlabel('Time (s)');
figure;
plot(time, energy_dissipated);
xlabel('Time (s)');
m = 2; % Mass (kg)
% Time settings
t_start = 0;
% Initial conditions
z0 = 0; % Initial position
v0 = 0; % Initial velocity
time = t_start:dt:t_end;
z = zeros(size(time));
v = zeros(size(time));
for i = 1:numel(time)
t = time(i);
% Calculate acceleration
F_t = F(t);
a = (F_t - b * v0 - k * z0) / m;
v1 = v0 + a * dt;
z1 = z0 + v1 * dt;
% Store values
v(i) = v1;
z(i) = z1;
v0 = v1;
z0 = z1;
end
% Plotting
plot(time, z);
xlabel('Time (s)');
ylabel('Response (z)');
title('Dynamic Response');
Problem 7.24
% System parameters
% Simulation time
t_start = 0;
t_end = 10;
dt = 0.001;
time = t_start:dt:t_end;
% Initial conditions
theta = zeros(size(time));
omega = zeros(size(time));
% Numerical integration using Euler's method
for i = 2:numel(time)
t = time(i);
omega_0 = omega(i);
theta_0 = theta(i);
end
% Plotting
plot(time, theta);
xlabel('Time (s)');
num = 800;
G = tf(num, den);
poles = pole(G);
disp(poles);
t = 0:0.01:10;
u = ones(size(t));
plot(t, y);
xlabel('Time');
ylabel('Output');
num = 0.25;
G = tf(num, den);
t = 0:0.01:10;
u = 4 * ones(size(t));
plot(t, y);
xlabel('Time (s)');
ylabel('Position (m)');
% Initial conditions
x = y(:, 1);
v = y(:, 2);
figure;
subplot(2, 1, 1);
plot(t, x);
xlabel('Time (s)');
ylabel('Displacement (m)');
subplot(2, 1, 2);
plot(t, v);
xlabel('Time (s)');
ylabel('Velocity (m/s)');
Problem 7.16
% Define the state matrix A
B = [0; 1.5];
C = [1 0];
D = 0;
t = 0:0.1:10;
plot(t, y);
xlabel('Time');
ylabel('Output');
title('System Response');
grid on;
B = [0; 1.5];
C = [1 0];
D = 0;
% Create the state-space model
t = 0:0.1:10;
plot(t, y);
xlabel('Time');
ylabel('Output');
grid on;
Problem 6.8
clc;
clear;
close all;
R1 = 0.4;
R2 = 0.2;
C = 0.04;
L = 0.01;
Q0 = 0.01;
V0 = Q0 / C;
t = 0:0.001:1.5;
plot(t, y);
xlabel('Time');
ylabel('Output');
title('System Response');
grid on;