-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcostFunctionPractice.m
executable file
·60 lines (51 loc) · 1.6 KB
/
costFunctionPractice.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
%find steady state indices based on angles
T = 50*5; %at least one period to define the range we'll use.
margin = 0.1; %what margin to use, so don't cut data off if just a little different
time = Salp1_angles.time;
angle2 = Salp1_angles.signals(2).values;
angle1 = Salp1_angles.signals(1).values;
L = length(angle1);
min1 = min(angle1(L-T:L));
min1 = min1-margin*abs(min1);
max1 = max(angle1(L-T:L));
max1 = max1+margin*abs(max1);
min2 = min(angle2(L-T:L));
min2 = min2-margin*abs(min2);
max2 = max(angle2(L-T:L));
max2 = max2+margin*abs(max2);
smallestIndex = L-T;
jump = T;
while(smallestIndex > T)
angle1Part = angle1(smallestIndex-jump:smallestIndex);
angle2Part = angle2(smallestIndex-jump:smallestIndex);
if(min(angle1Part) > min1 && min(angle2Part) > min2 && ...
max(angle1Part) < max1 && max(angle2Part) < max2)
smallestIndex = smallestIndex-jump;
else
break;
end
end
%
% figure(1)
% plot(time(1:smallestIndex), angle1(1:smallestIndex), 'r');
% hold on;
% plot(time(smallestIndex: L), angle1(smallestIndex:L), 'b');
% plot(time, min1*ones(L,1), '--k');
% plot(time, max1*ones(L,1), '--k');
% hold off;
% title('angle1');
% axis([0 time(L) min1-0.1 max1+0.1]);
%
% figure(2);
% plot(time(1:smallestIndex), angle2(1:smallestIndex), 'r');
% hold on;
% plot(time(smallestIndex: L), angle2(smallestIndex:L), 'b');
% plot(time, min2*ones(L,1), '--k');
% plot(time, max2*ones(L,1), '--k');
% hold off;
% title('angle2');
% axis([0 time(L) min2-0.1 max2+0.1]);
velocities = Salp1_PandV.signals(2).values(smallestIndex:L, :);
velocity = sqrt(sum(velocities.^2,2));
avgVeloc = mean(velocity);
cost = -avgVeloc;