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.
- Loading branch information
Showing
17 changed files
with
109 additions
and
18 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
13 changes: 3 additions & 10 deletions
13
Math-ODE.package/ExplicitStepper.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 |
---|---|---|
@@ -1,13 +1,6 @@ | ||
stepping | ||
doStep: aState time: t stepSize: dt | ||
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. The default implementation here is Euler Method. Subclasses should override" | ||
| dxdt | | ||
dxdt := system x: aState t: t. | ||
aState isNumber | ||
ifTrue: [^ (dt * dxdt + aState)] | ||
ifFalse: | ||
[(1 to aState size) | ||
do: [:i | | xi | | ||
xi := aState at: i. | ||
aState at: i put: (dxdt at: i) * dt + xi]. | ||
^ aState.] | ||
self stepSize: timeStep. | ||
^ self doStep: aState time: t. |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
A RungeKuttaStepper is a specialization on Explicit Stepper that provides a higer order estimate. The Euler method implemented in ExplicitStepper is order 1, and the error obtained is proportional to the step size. | ||
|
||
The RungeKuttaStepper is order 4, the error term is proportional to the step size to the fourth power. |
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 @@ | ||
accessing | ||
order | ||
"RungeKutta is a fourth order method." | ||
^ 4 |
13 changes: 13 additions & 0 deletions
13
Math-ODE.package/RungeKuttaStepper.class/instance/collectionDoStep.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,13 @@ | ||
stepping | ||
collectionDoStep: aState time: t | ||
"aState is a collection/vector, and system is a vector function. Take a single step using fourth order runge-kutta." | ||
| k1 k2 k3 k4 midPoint endPoint| | ||
midPoint := self stepSize / 2 + t. | ||
endPoint := self stepSize + t. | ||
k1 := system x: aState t: t. | ||
k2 := system x: aState + (k1 * self stepSize / 2) t: midPoint. | ||
k3 := system x: aState + (k2 * self stepSize / 2 ) t: midPoint. | ||
k4 := system x: aState + (k3 * self stepSize) t: endPoint. | ||
Transcript show: t; show: aState; cr. | ||
^ aState + ((k1 + k2 + k2 + k3 + k3 + k4) / 6 * self stepSize). | ||
|
10 changes: 10 additions & 0 deletions
10
Math-ODE.package/RungeKuttaStepper.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,10 @@ | ||
stepping | ||
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 numberDoStep: aState time: t)] | ||
"a collection" | ||
ifFalse: | ||
[^ (self collectionDoStep: aState time: t)] |
9 changes: 9 additions & 0 deletions
9
Math-ODE.package/RungeKuttaStepper.class/instance/numberDoStep.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,9 @@ | ||
stepping | ||
numberDoStep: aState time: t | ||
"state is a number. Take a single step at t." | ||
| k1 k2 k3 k4 | | ||
k1 := system x: aState t: t. | ||
k2 := system x: aState + (k1 * self stepSize / 2 ) t: self stepSize / 2 + t. | ||
k3 := system x: aState + (k2 * self stepSize / 2 ) t: self stepSize / 2 + t. | ||
k4 := system x: aState + (self stepSize * k3) t: self stepSize + t. | ||
^ aState + ((k1 + k2 + k2 + k3 + k3 + k4)/ 6 * self stepSize). |
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,16 @@ | ||
{ | ||
"category" : "Math-ODE", | ||
"classinstvars" : [ | ||
], | ||
"classtraitcomposition" : "{}", | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "<historical>", | ||
"instvars" : [ | ||
], | ||
"name" : "RungeKuttaStepper", | ||
"pools" : [ | ||
], | ||
"super" : "ExplicitStepper", | ||
"traitcomposition" : "{}", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
SystemOrganization addCategory: #'Math-ODE'! | ||
SystemOrganization addCategory: #'Math-ODE-Tests'! |
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
Empty file.
9 changes: 9 additions & 0 deletions
9
Math-ODETests.package/RungeKuttaStepperTest.class/instance/testSimpleSystem.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,9 @@ | ||
as yet unclassified | ||
testSimpleSystem | ||
| solver stepper system dt | | ||
dt := 0.01. | ||
system := ExplicitSystem block: [:x :t | t sin]. | ||
stepper := RungeKuttaStepper onSystem: system. | ||
solver := (ODESolver new) stepper: stepper; system: system; dt: dt. | ||
self should: [(solver solve: system startState: -1 startTime: 0 endTime: Float pi) closeTo: 1]. | ||
|
12 changes: 12 additions & 0 deletions
12
Math-ODETests.package/RungeKuttaStepperTest.class/instance/testVectorSystem.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,12 @@ | ||
as yet unclassified | ||
testVectorSystem | ||
| solver stepper system dt | | ||
dt := 0.01. | ||
system := ExplicitSystem block: [:x :t | | c | c:= DhbVector new: 2. | ||
c at: 1 put: t sin. | ||
c at: 2 put: t cos. | ||
c]. | ||
stepper := RungeKuttaStepper onSystem: system. | ||
solver := (ODESolver new) stepper: stepper; system: system; dt: dt. | ||
self should: [((solver solve: system startState: #(-1 0) startTime: 0 endTime: Float pi ) at: 1)closeTo: 1]. | ||
self should: [((solver solve: system startState: #(-1 0) startTime: 0 endTime: Float pi / 2 ) at: 2 ) closeTo: 1]. |
16 changes: 16 additions & 0 deletions
16
Math-ODETests.package/RungeKuttaStepperTest.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,16 @@ | ||
{ | ||
"category" : "Math-ODETests", | ||
"classinstvars" : [ | ||
], | ||
"classtraitcomposition" : "{}", | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "", | ||
"instvars" : [ | ||
], | ||
"name" : "RungeKuttaStepperTest", | ||
"pools" : [ | ||
], | ||
"super" : "TestCase", | ||
"traitcomposition" : "{}", | ||
"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