-
-
Notifications
You must be signed in to change notification settings - Fork 232
Transformation function to turn FDEs into ODEs #3776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fchen121
wants to merge
23
commits into
SciML:master
Choose a base branch
from
fchen121:iss3707
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f9f5257
Created FDE to ODE for one equation with alpha < 1
80091f1
Merge branch 'SciML:master' into iss3707
fchen121 6fd7d31
Implement FDE to ODE for single equation with alpha > 1
8a1101d
Update FDE_to_ODE to handle multiple FDEs
8d21234
Fix bug in FDE to ODE for alpha > 1
b936c8b
Create test case for FDE to ODE
06d5699
Merge branch 'SciML:master' into iss3707
fchen121 90534fa
Add docstring to fractional_to_ordinary
ee6a7e5
Merge branch 'SciML:master' into iss3707
fchen121 17f978b
Add new function to deal with multiple term problem
970b404
Merge branch 'SciML:master' into iss3707
fchen121 4efd06f
Improve test cases
4f0753c
Update docstring
9237e47
Merge branch 'SciML:master' into iss3707
fchen121 4293364
Merge branch 'SciML:master' into iss3707
fchen121 9480748
Implemented matrix ver. and changed test cases
8cf8960
Merge branch 'SciML:master' into iss3707
fchen121 c64979c
Combined matrix ver. with regular
a01857f
Added matrix form for linear FDE to ODE and new test case
b094647
Fix merge issue
68a9807
Merge branch 'SciML:master' into iss3707
fchen121 1b6ea2d
Fix function format
0506d04
Add new function to doc and fix export issue
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
using ModelingToolkit, OrdinaryDiffEq, ODEInterfaceDiffEq, SpecialFunctions, LinearAlgebra | ||
using Test | ||
|
||
# Testing for α < 1 | ||
# Uses example 1 from Section 7 of https://arxiv.org/pdf/2506.04188 | ||
@independent_variables t | ||
@variables x(t) | ||
D = Differential(t) | ||
tspan = (0., 1.) | ||
timepoint = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.] | ||
|
||
function expect(t, α) | ||
return (3/2*t^(α/2) - t^4)^2 | ||
end | ||
|
||
α = 0.5 | ||
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2)) | ||
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2) | ||
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1) | ||
|
||
prob = ODEProblem(sys, [], tspan) | ||
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10) | ||
|
||
time = 0 | ||
while(time <= 1) | ||
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7) | ||
time += 0.1 | ||
end | ||
|
||
α = 0.3 | ||
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2)) | ||
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2) | ||
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1; matrix=true) | ||
|
||
prob = ODEProblem(sys, [], tspan) | ||
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10) | ||
|
||
time = 0 | ||
while(time <= 1) | ||
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7) | ||
time += 0.1 | ||
end | ||
|
||
α = 0.9 | ||
eqs = (9*gamma(1 + α)/4) - (3*t^(4 - α/2)*gamma(5 + α/2)/gamma(5 - α/2)) | ||
eqs += (gamma(9)*t^(8 - α)/gamma(9 - α)) + (3/2*t^(α/2)-t^4)^3 - x^(3/2) | ||
sys = fractional_to_ordinary(eqs, x, α, 10^-7, 1) | ||
|
||
prob = ODEProblem(sys, [], tspan) | ||
sol = solve(prob, radau5(), saveat=timepoint, abstol = 1e-10, reltol = 1e-10) | ||
|
||
time = 0 | ||
while(time <= 1) | ||
@test isapprox(expect(time, α), sol(time, idxs=x), atol=1e-7) | ||
time += 0.1 | ||
end | ||
|
||
# Testing for example 2 of Section 7 | ||
@independent_variables t | ||
@variables x(t) y(t) | ||
D = Differential(t) | ||
tspan = (0., 220.) | ||
|
||
sys = fractional_to_ordinary([1 - 4*x + x^2 * y, 3*x - x^2 * y], [x, y], [1.3, 0.8], 10^-8, 220; initials=[[1.2, 1], 2.8]; matrix=true) | ||
prob = ODEProblem(sys, [], tspan) | ||
sol = solve(prob, radau5(), abstol = 1e-8, reltol = 1e-8) | ||
|
||
@test isapprox(1.0097684171, sol(220, idxs=x), atol=1e-5) | ||
@test isapprox(2.1581264031, sol(220, idxs=y), atol=1e-5) | ||
|
||
#Testing for example 3 of Section 7 | ||
@independent_variables t | ||
@variables x_0(t) | ||
D = Differential(t) | ||
tspan = (0., 5000.) | ||
|
||
function expect(t) | ||
return sqrt(2) * sin(t + pi/4) | ||
end | ||
|
||
sys = linear_fractional_to_ordinary([3, 2.5, 2, 1, .5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t), 10^-5, 5000; initials=[1, 1, -1]) | ||
prob = ODEProblem(sys, [], tspan) | ||
sol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5) | ||
|
||
@test isapprox(expect(5000), sol(5000, idxs=x_0), atol=1e-5) | ||
|
||
msys = linear_fractional_to_ordinary([3, 2.5, 2, 1, .5, 0], [1, 1, 1, 4, 1, 4], 6*cos(t), 10^-5, 5000; initials=[1, 1, -1], matrix=true) | ||
mprob = ODEProblem(sys, [], tspan) | ||
msol = solve(prob, radau5(), abstol = 1e-5, reltol = 1e-5) | ||
|
||
@test isapprox(expect(5000), msol(5000, idxs=x_0), atol=1e-5) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gamma isn't defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gamma should be the gamma function from SpecialFunctions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 ahhh makes sense.