-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinDamped.mpl
More file actions
executable file
·66 lines (48 loc) · 1.5 KB
/
LinDamped.mpl
File metadata and controls
executable file
·66 lines (48 loc) · 1.5 KB
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
#!/home/tzdyrski/bin/maple -q
#
# Solves the Linear damped oscillator using the method of multiple scales.
#
# Written for Maple 2017
# Thomas Zdyrski (tzdyrski@ucsd.edu)
# 10 April 2018
restart():
LinDamped := module()
export
UnitTests,
LinDamped:
UnitTests := proc()
description "Run unit tests.":
# Test 1st-order LinDamped procedure
CodeTools:-Test(LinDamped(1),
{[y(t) = exp(-t__1)*cos(1/2*t__1+t__0)+sin(t__0)*epsilon]},
label="1st-Order LinDamped Procedure Test"):
# Test 2nd-order LinDamped procedure
CodeTools:-Test(LinDamped(2),
{[y(t) =
exp(-t__1)*cos(-5/8*t__2+1/2*t__1+t__0)+exp(-t__1)*sin(1/2*t__1+t__0)*epsilon-1/2*sin(t__0)*epsilon^2]},
label="2nd-Order LinDamped Procedure Test"):
end proc:
LinDamped := proc(
e_order::integer:=1, # highest order in epsilon to keep (leading order is e_order 1)
{leading_order_eqs::integer:=0, # Leading order of perturbation expansion for dependent variable
t_num::integer:=e_order-leading_order_eqs+1}, # number of time scales to implement
$)
local
PDEs,
ICs:
# Load packages
read("MultipleScales.mpl"):
interface(ansi=true, errorbreak=2):
# Define our system of equations
PDEs := {diff(y(t),t,t) + (1+epsilon)*y(t) + 2*epsilon*diff(y(t),t) = 0}:
# Generate initial conditions
ICs := {y(0) = 1, D(y)(0)=0}:
# Solve equations
MultipleScales:-CompleteSystem(PDEs, e_order,
':-scales'=t, ':-leading_order_eqs'=leading_order_eqs,
'ICs'=ICs, ':-restrict_scales'=true):
return %:
end proc:
end module:
#LinDamped:-LinDamped(2):
#combine(%, trig);