-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolving_Equation_of_Motion.m
More file actions
139 lines (95 loc) · 2.67 KB
/
Solving_Equation_of_Motion.m
File metadata and controls
139 lines (95 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%% DESCRIPTON
%
% This is a script to solve the differential equation of a single mass
% system
%
%% OUTPUT
%
% Formatted figure of the displacement of single mass and system and its
% animation
%
%% VERSION
% Author: Neeraj Kulkarni
% Creation date: 22/07/2024
% Matlab version: matlab online
%
%% REVISION
%
% V1.0 | 22-Jul-2024 | Neeraj Kulkarni | Creation
%
%% PROGRAM
clear
clc
close all % closes all figures
%% 1.) Definition
%% 1.) -Parameter Definitions
mass = 750;
stiffness = 1000000;
damping = 5000;
time = 0:0.01:2;
x_0 = 0.01;
x_dot_0 = 0.1;
%% 2.) Computing
%% 2.) -Parameter calculation
dampingcoefficient = damping/(2*mass);
angulareigenfrequency = sqrt(stiffness/mass);
%% 2.) -Calculation of the characteristic polynomail
lambda = roots([1,2*dampingcoefficient,angulareigenfrequency^2]);
%% 2.) -Calculation of the constants
k1 = (x_dot_0 - lambda(2)*x_0)/(lambda(1)-lambda(2));
k2 = (lambda(1)*x_0 - x_dot_0)/(lambda(1)-lambda(2));
%% 2.) -Calculation of the solution
x_t_h = k1*exp(lambda(1)*time) + k2*exp(lambda(2)*time);
v_t_h = k1*lambda(1)*exp(lambda(1)*time) + k2*lambda(2)*exp(lambda(2)*time);
x_t = real(x_t_h);
v_t = real(v_t_h);
%% 3.) Plot
%% 3.) -Initialize Figures
run("Initialize_figures.m");
%% 3.) -Draw Ground
hold on;
run("Draw_ground.m");
%% 3.) -Draw Mass
run("Draw_mass.m");
%% 3.) -Draw Spring
run("Draw_spring.m");
%% 3.) -Draw damper
run("Draw_damper.m");
%% 3.) -Draw cos
run("Draw_cos.m");
%% 3.) -Plot animation
% initialize vectors
x_t_length = length(x_t);
t_plot = NaN(1,x_t_length);
x_t_plot = NaN(1,x_t_length);
v_t_plot = NaN(1,x_t_length);
u = 1;
for k = 1:x_t_length
cla
% Plot Graph
t_plot(k) = time(u);
x_t_plot(k) = x_t(u);
v_t_plot(k) = v_t(u);
set(graph_plot(1),'Parent', axes_graph(1),'XData',t_plot,'YData',x_t_plot);
set(graph_plot(2),'Parent', axes_graph(2),'XData',t_plot,'YData',v_t_plot);
%Plot Ground
plotcube(axes_ani, dimension_g, position_g,clr_g);
%Plot
position_m = [x_t(u) 0 0];
plotcube(axes_ani, dimension_m, position_m,clr_m);
%Plot spring
spring_head = x_t(u) + dimension_m(1)/2;
x_pos_spring = phi_s/phi_max*(spring_head - spring_foot) + spring_foot;
plot3(axes_ani, x_pos_spring, y_pos_spring, z_pos_spring, 'b','linewidth',lnwdth);
% Plot Damper
damper_head = x_t(u) + dimension_m(1)/2;
plotdamper(stroke_length_max, damper_foot, damper_head, y_offset_d,clr_d,lnwdth);
%Plot Cos
plotcos(x_ar, variable_cos, clr_cos, lnwdth, fntsz);
% Rotate View
view(90,-90);
title(title_ani,'FontSize',fntsz);
xlabel(xlabel_ani,'fontsize',fntsz);
drawnow
u=u+1;
end