-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patheqs.m
68 lines (59 loc) · 2.08 KB
/
eqs.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
function eqs = equations(P,B1) % returns vector of equations of motion projected in basis B1
p = P.p.dt;
F = anakin.tensor([0;0;0]); % allocate;
for i=1:length(P.forces)
F = F + P.forces{i};
end
if ~exist('B1','var')
B1 = anakin.basis;
elseif isa(B1,'anakin.frame')
B1 = B1.basis; % extract basis
end
eqs = sym([0;0;0]); % allocate
for i=1:3
p_ = p * B1.e(i);
F_ = F * B1.e(i);
eqs(i) = (p_.components == F_.components);
end
end
function eqs = equations(b,B1) % returns vector of equations of motion projected in basis B1
p = b.p.dt;
H = b.H.dt;
F = anakin.tensor([0;0;0]); % allocate;
M = anakin.tensor([0;0;0]); % allocate;
for i=1:length(b.forces)
F = F + b.forces{i};
M = M + b.torques{i};
end
if ~exist('B1','var')
B1 = anakin.basis;
elseif isa(B1,'anakin.frame')
B1 = B1.basis; % extract basis
end
eqs = sym([0;0;0]);
for i=1:3
p_ = p * B1.e(i);
F_ = F * B1.e(i);
eqs(i) = (p_.components == F_.components);
end
for i=1:3
H_ = H * B1.e(i);
M_ = M * B1.e(i);
eqs(3+i) = (H_.components == M_.components);
end
end
function test_eqs(~) % Equations
import anakin.*
if license('test','symbolic_toolbox')
syms t;
syms theta(t) xi(t);
assume([in(t, 'real'), in(theta(t), 'real'), in(xi(t), 'real'),...
in(diff(theta(t),t), 'real'), in(diff(xi(t),t), 'real')]);
c = formula([cos(theta);xi^2;xi]);
a = tensor(c);
mass = scalar(3);
P = particle(mass,a);
P.forces = {tensor([1,1,xi])};
eqs = P.equations;
end
end