forked from djuber/SciSmalltalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TrapezoidStepper and tests for it
- Loading branch information
Showing
22 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
as yet unclassified | ||
order | ||
"the default ImplicitStepper is a Backward Euler Method, order 1" | ||
^ 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"class" : { | ||
}, | ||
"order" : "NataliaMoskovchuk 7/9/2013 00:06" }, | ||
"instance" : { | ||
"doStep:time:" : "NataliaMoskovchuk 7/4/2013 00:24", | ||
"doStep:time:" : "NataliaMoskovchuk 7/9/2013 00:00", | ||
"doStep:time:stepSize:" : "NataliaMoskovchuk 7/4/2013 00:24", | ||
"stepSize" : "NataliaMoskovchuk 7/3/2013 10:35", | ||
"stepSize:" : "NataliaMoskovchuk 7/3/2013 10:34" } } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
as yet unclassified | ||
order | ||
"Trapezoid is a second order method." | ||
^ 2 |
17 changes: 17 additions & 0 deletions
17
Math-ODE.package/TrapezoidStepper.class/instance/doStep.time..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
as yet unclassified | ||
doStep: aState time: t | ||
"This method should take one step from inState at time t of size dt, and modify the state, then answer it. " | ||
self stepSize isNil ifTrue: [self error: 'step size required by stepper']. | ||
aState isNumber | ||
ifTrue: [^ (self stepSize * (system x: aState t: t) + aState)] | ||
"a collection" | ||
ifFalse: | ||
[(1 to: aState size) | ||
do: [ :i | | ||
| xi1 xi2 x0 ti | | ||
ti := t + self stepSize. | ||
x0 := aState at: i. | ||
xi1 := x0 + self stepSize* (system x: x0 t: t). "predict" | ||
xi2 := x0 + (1/2)*self stepSize*( (system x: x0 t: t) + (system x: xi1 t: ti) ). "correction 1" | ||
aState at: i put: x0 + (1/2)*self stepSize*( (system x: x0 t: t) + (system x: xi2 t: ti) ) ]. "correction 2" | ||
^ aState.] |
5 changes: 5 additions & 0 deletions
5
Math-ODE.package/TrapezoidStepper.class/instance/doStep.time.stepSize..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
as yet unclassified | ||
doStep: aState time: t stepSize: timeStep | ||
"This method should take one step from inState at time t of size dt, and modify the state, then answer it. " | ||
self stepSize: timeStep. | ||
^ self doStep: aState time: t. |
6 changes: 6 additions & 0 deletions
6
Math-ODE.package/TrapezoidStepper.class/methodProperties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"class" : { | ||
"order" : "NataliaMoskovchuk 7/9/2013 00:05" }, | ||
"instance" : { | ||
"doStep:time:" : "NataliaMoskovchuk 7/9/2013 00:05", | ||
"doStep:time:stepSize:" : "NataliaMoskovchuk 7/9/2013 00:05" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"category" : "Math-ODE", | ||
"classinstvars" : [ | ||
], | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "", | ||
"instvars" : [ | ||
], | ||
"name" : "TrapezoidStepper", | ||
"pools" : [ | ||
], | ||
"super" : "ImplicitStepper", | ||
"type" : "normal" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Math-ODETests.package/ImplicitStepperTest.class/instance/testDoStepTime.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
as yet unclassified | ||
testDoStepTime | ||
"this is identical to testDoStepTimeStepSize except dt is stored." | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | x * t]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
stepper stepSize: dt. | ||
self should: [stepper stepSize = dt]. | ||
self should: [(stepper doStep: 0 time: 10) = 0 ]. | ||
self should: [(stepper doStep: 10 time: 0 stepSize: 1) = 10 ]. | ||
|
||
"stepSize parameter changes the stored stepSize" | ||
self should: [(stepper stepSize = 1)]. | ||
|
||
self should: [(stepper doStep: 1 time: 1) = 2]. | ||
self should: [(stepper doStep: 10 time: 1 stepSize: 0.2) = 12.0]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
17 changes: 17 additions & 0 deletions
17
Math-ODETests.package/TrapezoidStepperTest.class/instance/testDoStepTime.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
as yet unclassified | ||
testDoStepTime | ||
"this is identical to testDoStepTimeStepSize except dt is stored." | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | x * t]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
stepper stepSize: dt. | ||
self should: [stepper stepSize = dt]. | ||
self should: [(stepper doStep: 0 time: 10) = 0 ]. | ||
self should: [(stepper doStep: 10 time: 0 stepSize: 1) = 10 ]. | ||
|
||
"stepSize parameter changes the stored stepSize" | ||
self should: [(stepper stepSize = 1)]. | ||
|
||
self should: [(stepper doStep: 1 time: 1) = 2]. | ||
self should: [(stepper doStep: 10 time: 1 stepSize: 0.2) = 12.0]. |
15 changes: 15 additions & 0 deletions
15
Math-ODETests.package/TrapezoidStepperTest.class/instance/testDoStepTime1.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
as yet unclassified | ||
testDoStepTime1 | ||
"this is identical to testDoStepTimeStepSize except dt is stored." | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | 3 * t negated exp - (0.4 * x)]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
stepper stepSize: dt. | ||
self should: [stepper stepSize = dt]. | ||
self should: [(stepper doStep: 0 time: 10) = 1.3619978928745448e-5 ]. | ||
self should: [(stepper doStep: 10 time: 0 stepSize: 1) = 9.0 ]. | ||
|
||
"stepSize parameter changes the stored stepSize" | ||
|
||
self should: [(stepper doStep: 5 time: 0 stepSize: 1.5) = 6.5]. |
10 changes: 10 additions & 0 deletions
10
Math-ODETests.package/TrapezoidStepperTest.class/instance/testDoStepTimeStepSize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
as yet unclassified | ||
testDoStepTimeStepSize | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | t sin]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
self should: [(stepper doStep: 0 time: 10 stepSize: dt) = -0.05440211108893698 ]. | ||
self should: [(stepper doStep: 10 time: 0 stepSize: dt) = 10.0 ]. | ||
self should: [(stepper doStep: 1 time: 1 stepSize: dt) =1.0841470984807897]. | ||
self should: [(stepper doStep: 10 time: 1 stepSize: dt) = 10.08414709848079]. |
10 changes: 10 additions & 0 deletions
10
Math-ODETests.package/TrapezoidStepperTest.class/instance/testDoStepTimeStepSize1.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
as yet unclassified | ||
testDoStepTimeStepSize1 | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | x * t]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
self should: [(stepper doStep: 0 time: 10 stepSize: dt) = 0.0 ]. | ||
self should: [(stepper doStep: 10 time: 0 stepSize: dt) = 10.0 ]. | ||
self should: [(stepper doStep: 1 time: 1 stepSize: dt) = 1.1]. | ||
self should: [(stepper doStep: 10 time: 1 stepSize: dt) = 11.0]. |
8 changes: 8 additions & 0 deletions
8
Math-ODETests.package/TrapezoidStepperTest.class/instance/testDoStepTimeStepSize2.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
as yet unclassified | ||
testDoStepTimeStepSize2 | ||
| stepper sys dt | | ||
sys := ImplicitSystem block: [:x :t | 3 * t negated exp - (0.4 * x)]. | ||
stepper := ImplicitStepper onSystem: sys. | ||
dt := 0.1. | ||
self should: [(stepper doStep: 1 time: 1 stepSize: dt) = 1.0703638323514326]. | ||
self should: [(stepper doStep: 10 time: 1 stepSize: dt) = 9.710363832351433]. |
3 changes: 3 additions & 0 deletions
3
Math-ODETests.package/TrapezoidStepperTest.class/instance/testOrderIsTwo.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
as yet unclassified | ||
testOrderIsTwo | ||
self should: [TrapezoidStepper order = 2] |
10 changes: 10 additions & 0 deletions
10
Math-ODETests.package/TrapezoidStepperTest.class/methodProperties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"class" : { | ||
}, | ||
"instance" : { | ||
"testDoStepTime" : "NataliaMoskovchuk 7/9/2013 00:07", | ||
"testDoStepTime1" : "NataliaMoskovchuk 7/9/2013 00:08", | ||
"testDoStepTimeStepSize" : "NataliaMoskovchuk 7/9/2013 00:08", | ||
"testDoStepTimeStepSize1" : "NataliaMoskovchuk 7/9/2013 00:08", | ||
"testDoStepTimeStepSize2" : "NataliaMoskovchuk 7/9/2013 00:09", | ||
"testOrderIsTwo" : "NataliaMoskovchuk 7/9/2013 00:09" } } |
14 changes: 14 additions & 0 deletions
14
Math-ODETests.package/TrapezoidStepperTest.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"category" : "Math-ODETests", | ||
"classinstvars" : [ | ||
], | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "", | ||
"instvars" : [ | ||
], | ||
"name" : "TrapezoidStepperTest", | ||
"pools" : [ | ||
], | ||
"super" : "TestCase", | ||
"type" : "normal" } |
Oops, something went wrong.