-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolucao.m
288 lines (236 loc) · 8.86 KB
/
resolucao.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
%% Import data from text file.
% Script for importing data from the following text file:
%
% E:\2020\HACKATON\trajeto_campus_FGA.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2020/09/25 14:41:06
%% Initialize variables.
filename = 'D:\Downloads\trajeto_campus_FGA.csv';
delimiter = ',';
startRow = 2;
%% Format for each line of text:
% column2: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%*q%f%*s%*s%*s%*s%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Create output variable
trajetocampusFGAY = [dataArray{1:end-1}];
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%% Import data from text file.
% Script for importing data from the following text file:
%
% E:\2020\HACKATON\trajeto_campus_FGA.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2020/09/25 13:50:18
%% Initialize variables.
filename = 'D:\Downloads\trajeto_campus_FGA.csv';
delimiter = ',';
startRow = 2;
%% Read columns of data as text:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%*q%*q%*q%q%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%% Close the text file.
fclose(fileID);
%% Convert the contents of columns containing numeric text to numbers.
% Replace non-numeric text with NaN.
raw = repmat({''},length(dataArray{1}),length(dataArray)-1);
for col=1:length(dataArray)-1
raw(1:length(dataArray{col}),col) = mat2cell(dataArray{col}, ones(length(dataArray{col}), 1));
end
numericData = NaN(size(dataArray{1},1),size(dataArray,2));
% Converts text in the input cell array to numbers. Replaced non-numeric
% text with NaN.
rawData = dataArray{1};
for row=1:size(rawData, 1)
% Create a regular expression to detect and remove non-numeric prefixes and
% suffixes.
regexstr = '(?<prefix>.*?)(?<numbers>([-]*(\d+[\,]*)+[\.]{0,1}\d*[eEdD]{0,1}[-+]*\d*[i]{0,1})|([-]*(\d+[\,]*)*[\.]{1,1}\d+[eEdD]{0,1}[-+]*\d*[i]{0,1}))(?<suffix>.*)';
try
result = regexp(rawData(row), regexstr, 'names');
numbers = result.numbers;
% Detected commas in non-thousand locations.
invalidThousandsSeparator = false;
if numbers.contains(',')
thousandsRegExp = '^[-/+]*\d+?(\,\d{3})*\.{0,1}\d*$';
if isempty(regexp(numbers, thousandsRegExp, 'once'))
numbers = NaN;
invalidThousandsSeparator = true;
end
end
% Convert numeric text to numbers.
if ~invalidThousandsSeparator
numbers = textscan(char(strrep(numbers, ',', '')), '%f');
numericData(row, 1) = numbers{1};
raw{row, 1} = numbers{1};
end
catch
raw{row, 1} = rawData{row};
end
end
%% Create output variable
trajetocampusFGAt = cell2mat(raw);
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans raw col numericData rawData row regexstr result numbers invalidThousandsSeparator thousandsRegExp;
%% Import data from text file.
% Script for importing data from the following text file:
%
% E:\2020\HACKATON\trajeto_campus_FGA.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2020/09/25 13:53:15
%% Initialize variables.
filename = 'D:\Downloads\trajeto_campus_FGA.csv';
delimiter = ',';
startRow = 2;
%% Format for each line of text:
% column3: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%*q%*q%f%*s%*s%*s%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Create output variable
trajetocampusFGAZ = [dataArray{1:end-1}];
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%% Import data from text file.
% Script for importing data from the following text file:
%
% E:\2020\HACKATON\trajeto_campus_FGA.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2020/09/25 13:47:44
%% Initialize variables.
filename = 'D:\Downloads\trajeto_campus_FGA.csv';
delimiter = ',';
startRow = 2;
%% Format for each line of text:
% column1: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%*s%*s%*s%*s%*s%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Create output variable
trajetocampusFGAX = [dataArray{1:end-1}];
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%%Vetor de velocidades
V = zeros(1,313);
%%Iterar para calcular o deslocamento do carro ponto a ponto
for i=1:313
if i>1
V(i) = sqrt((trajetocampusFGAX(i)-trajetocampusFGAX(i-1))^2+(trajetocampusFGAZ(i)-trajetocampusFGAZ(i-1))^2+(trajetocampusFGAY(i)-trajetocampusFGAY(i-1))^2);
else
V(i) = 0;
end
end
%%Constantes
M = 600;
g = 9.8;
Crr1 = 0.127;
Crr2 = 0.000116;
Rho = 1.1241;
Cd = 1;
Af = 2.5;
dV = diff(V);
x = zeros (1,312);
y = zeros (1,312);
F = zeros (1,312);
Fa = zeros (1,312);
Fi = zeros (1,312);
Fr = zeros (1,312);
P = zeros (1,312);
Pi = zeros (1,312);
Pr = zeros (1,312);
%%Calculo das forcas no veiculo
for t=1:312
x(t)=t;
b = V(t);
Fa(t) = 0.5*Cd*Rho*Af*b^2;
Fr(t) = (Crr1+ (Crr2*b))*M;
Fi(t) = M*dV(t);
F(t) = Fa(t) + Fr(t) + Fi(t);
end
Potmed = 0;
%%Calculo da potencia
for u=1:312
y(t)=u;
c = V(u);
Pa(u) = Fa(u)*c;
Pr(u) = Fr(u)*c;
Pi(u) = Fi(u)*c;
P(u) = Pi(u) + Pr(u) + Pa(u);
if P(u) < 0
P(u) = 0;
end
Potmed = Potmed + abs(P(u));
end
Potmed = Potmed/312;
figure(1);
plot(trajetocampusFGAt, V,'b');
grid on
grid minor
title('Perfil de velocidade');
xlabel('tempo (s)');
ylabel('Velocidade (m/s)');
figure(2);
plot(x,P,'b');
yline(Potmed,'r');
grid on
grid minor
title('Potência (Watts)');
xlabel('Tempo (s)');
ylabel('Watts (W)');
dim = [.3 .5 .3 .3];
str = 'Potência média = 2329,10 W';
annotation('textbox',dim,'String',str,'FitBoxToText','on');