-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegrator.m
73 lines (63 loc) · 2.36 KB
/
Integrator.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
%{
...
Created on 24/2/2020 16:11
This File is used for Integration uses "ODE113" - which uses "Adam
BashForth Moulton" Integration method
Inputs
1) G_var - Requisite Global data
2) fun - Function to be integrated.
3) x0 - Initial Condition vector
4) tspan - Time duration of integration(Refer MATLAB's help for ODE's on
supplying tspan)
4) type - 'forward' or 'backward' integration.
Outputs
Same as the outputs of ODE113,
1) t - Time values
2) x - Integrated xValues.
Note
-----
This file can also be used for "ODE events" function , when calling call will the options
"XYZ.IntFunc.ODEoptionsEvents" from "GlobalData". the events function is explicit for
Circular Restrcited Three Body Problem. Change if you want.
Dependencies
------------
1) MATLAB inbuilt ODE113 integrator
%}
function [t,x] = Integrator(G_var,fun,x0,tspan,type,section)
if nargin<3
disp('provide function and/or initial condition')
elseif nargin == 3
tspan = [0 10];
type = 'forward';
elseif nargin == 4
type = 'forward';
end
switch type
case 'forward'
options = G_var.IntFunc.ODEoptions;
[t,x] = ode113(fun,tspan,x0,options);
case 'backward'
options = G_var.IntFunc.ODEoptions;
[t,x] = ode113(fun,-tspan,x0,options);
case 'Events'
EventFunc = @(t,x) Events_cres(t,x,G_var);
options = odeset('Reltol',1e-12,'Abstol',1e-12,'Events',EventFunc);
[t,x]=ode113(fun,tspan,x0,options);
case 'backwardStopAtSOE'
EventFunc = @(t,x) EventsSOE(t,x,G_var);
options = odeset('Reltol',1e-12,'Abstol',1e-12,'Events',EventFunc);
[t,x]=ode113(fun,-tspan,x0,options);
case 'forwardStopAtSOE'
EventFunc = @(t,x) EventsSOE(t,x,G_var);
options = odeset('Reltol',1e-12,'Abstol',1e-12,'Events',EventFunc);
[t,x]=ode113(fun,tspan,x0,options);
case 'forwardPoincareSection'
EventFunc = @(t,x) Events_poincareSection(t,x,G_var,section);
options = odeset('Reltol',1e-12,'Abstol',1e-12,'Events',EventFunc);
[t,x]=ode113(fun,tspan,x0,options);
case 'backwardPoincareSection'
EventFunc = @(t,x) Events_poincareSection(t,x,G_var,section);
options = odeset('Reltol',1e-12,'Abstol',1e-12,'Events',EventFunc);
[t,x]=ode113(fun,-tspan,x0,options);
end
end