-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab1.m
executable file
·174 lines (140 loc) · 3.7 KB
/
lab1.m
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
clear;clc;close all;
% ------ Shared graph settings -------
gcaSettings = {...
'XGrid','on',...
'YGrid', 'on',...
'Fontsize', 13,...
'linewidth', 1,...
'FontName', 'AvantGarde'};
labelSettings = {...
'Interpreter','latex'...
'Fontsize', 17};
% -------------------------------------
Data =[...
0 0 0 0;...
0.36 0.293 0.308 0.297;...
0.50 0.363 0.348 0.360;...
0.72 0.424 0.404 0.412;...
0.90 0.463 0.463 0.466;...
1.08 0.538 0.504 0.509;...
1.44 0.601 0.592 0.605;...
1.80 0.712 0.686 0.669;...
2.16 0.745 0.747 0.751;...
2.52 0.816 0.820 0.816;...
2.88 0.888 0.889 0.893;...
3.24 0.959 0.964 0.956;...
3.60 1.026 1.025 1.026;...
3.96 1.090 1.089 1.091;...
4.32 1.161 1.158 1.161;...
4.68 1.219 1.223 1.212;...
5.00 1.279 1.277 1.277;...
5.40 1.353 1.339 1.336;...
5.80 1.398 1.386 1.382;...
6.20 1.468 1.471 1.482;...
6.60 1.545 1.550 1.541;...
7.00 1.627 1.614 1.614;...
7.40 1.689 1.695 1.702;...
7.80 1.751 1.762 1.761;...
8.20 1.826 1.834 1.834;...
8.60 1.903 1.894 1.903;...
9.00 1.967 1.965 1.945];
y = Data(:,1);
% Error in data collection that has to be added
S = -0.11;
for i=1:length(y)
if ~(i == 1 || i == 2 || i == 3 )
y(i) = y(i) + S;
end
end
t_avg = mean(Data(:,2:4),2);
t_deviation = (max(Data(:,2:4),[],2) - min(Data(:,2:4),[],2)); % ms
figure(1)
plot(t_avg,y,'*')
title('Stracka-tid-diagram','Interpreter','latex')
set(gca,gcaSettings(1:2:end),gcaSettings(2:2:end))
xlabel('$t$/$s$', labelSettings(1:2:end), labelSettings(2:2:end))
ylabel('$h$/$m$', labelSettings(1:2:end), labelSettings(2:2:end))
%% Momentan 1
dy = diff(y);
dt = diff(t_avg);
v = dy./dt;
figure(2)
plot([0 t_avg(2:size(t_avg,1))'], [0 v'],'*')
title('Hastighet-tid-diagram','Interpreter','latex')
set(gca,gcaSettings(1:2:end),gcaSettings(2:2:end))
xlabel('$t$/$s$', labelSettings(1:2:end), labelSettings(2:2:end))
ylabel('$v$/$ms^{-1}$', labelSettings(1:2:end), labelSettings(2:2:end))
%% Momentan 2 A
grad = 4;
p_s = polyfit(t_avg, y, grad);
sim_y = polyval(p_s, t_avg);
figure(1)
hold on
plot(t_avg, sim_y)
%% Momentan 2 B
p_v = polyder(p_s);
sim_v = polyval(p_v, t_avg);
figure(2)
hold on
plot(t_avg, sim_v)
%% Momentan 2 C
p_a = polyder(polyder(p_s));
sim_a = polyval(p_a,t_avg);
figure(3)
hold on
plot(t_avg, sim_a)
title('Acceleration-tid-diagram','Interpreter','latex')
set(gca,gcaSettings(1:2:end),gcaSettings(2:2:end))
xlabel('$t$/$s$', labelSettings(1:2:end), labelSettings(2:2:end))
ylabel('$a$/$ms^{-2}$', labelSettings(1:2:end), labelSettings(2:2:end))
%% Simulering
g = 9.81;
v(1) = 0;
s(1) = 0;
dt = 0.001;
t_i = 0;
t_f = 2;
t = linspace(t_i,t_f, (t_f-t_i)/dt);
N = length(t);
%% F_f = 0
for i=1:N
a(i) = g;
v(i+1) = v(i) + a(i)*dt;
s(i+1) = s(i) + v(i)*dt;
end
figure(1)
plot(t,s(1:N),'k--')
figure(2)
plot(t,v(1:N),'k--')
figure(3)
plot(t,a(1:N),'k--')
%% F_f = bv
for i=1:N
a(i) = g*(1-v(i)/6);
v(i+1) = v(i) + a(i)*dt;
s(i+1) = s(i) + v(i)*dt;
end
figure(1)
plot(t,s(1:N),'k-.')
figure(2)
plot(t,v(1:N),'k-.')
figure(3)
plot(t,a(1:N),'k-.')
%% F_f = Bv^2
for i=1:N
a(i) = g*(1-(v(i)/6)^2);
v(i+1) = v(i) + a(i)*dt;
s(i+1) = s(i) + v(i)*dt;
end
figure(1)
plot(t,s(1:N),'k-')
legend('Experimentella värden','Anpassning','Sim. utan luftmotstånd',...
'Sim. linjärt luftmotstånd','Sim. kvadratiskt luftmotstånd');
figure(2)
plot(t,v(1:N),'k-')
legend('Beräknat från exp. värden','Anpassning','Sim. utan luftmotstånd',...
'Sim. linjärt luftmotstånd','Sim. kvadratiskt luftmotstånd');
figure(3)
plot(t,a(1:N),'k-')
legend('Beräknat från exp. värden','Sim. utan luftmotstånd',...
'Sim. linjärt luftmotstånd','Sim. kvadratiskt luftmotstånd');