-
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.
Update adaptave integration to return an estimate of the tolerance Add package for Ordinary Differential Equations Add Euler's method for differential equations Add 4th order Runge-Kutta method for differential equations
- Loading branch information
1 parent
f56c9e7
commit f143e9d
Showing
5 changed files
with
119 additions
and
24 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
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,26 @@ | ||
with Ada.Text_IO; | ||
package body BBS.Numerical.ode_real is | ||
package float_io is new Ada.Text_IO.Float_IO(f'Base); | ||
-- | ||
-- Euler's method | ||
-- | ||
function euler(tf : test_func; start, initial, step : f'Base) return f'Base is | ||
begin | ||
return initial + step*tf(start, initial); | ||
end; | ||
-- | ||
-- 4th order Runge-Kutta method - single step | ||
-- | ||
function rk4(tf : test_func; start, initial, step : f'Base) return f'Base is | ||
k1 : f'Base; | ||
k2 : f'Base; | ||
k3 : f'Base; | ||
k4 : f'Base; | ||
begin | ||
k1 := step*tf(start, initial); | ||
k2 := step*tf(start + step/2.0, initial + k1/2.0); | ||
k3 := step*tf(start + step/2.0, initial + k2/2.0); | ||
k4 := step*tf(start + step, initial + k3); | ||
return initial + (k1 + 2.0*k2 + 2.0*k3 + k4)/6.0; | ||
end; | ||
end BBS.Numerical.ode_real; |
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 @@ | ||
generic | ||
type F is digits <>; | ||
package BBS.Numerical.ode_real is | ||
-- | ||
-- Define a type for the function to integrate. | ||
-- | ||
type test_func is access function (t, y : f'Base) return f'Base; | ||
-- | ||
-- Euler's method | ||
-- | ||
function euler(tf : test_func; start, initial, step : f'Base) return f'Base; | ||
-- | ||
-- 4th order Runge-Kutta method - single step | ||
-- | ||
function rk4(tf : test_func; start, initial, step : f'Base) return f'Base; | ||
-- | ||
end BBS.Numerical.ode_real; |
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