-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add @ivp macro #137
Comments
What about extending the julia> @system(x' = -x, x(0) ∈ Interval(-1.0, 1.0)) |
Ok, good idea 👍 . We can extend P = @ivp x' = -x, x(0) ∈ Interval(-1.0, 1.0)
solve(P, T=1.0) |
So, the |
Yes, that's exactly what i have in mind so far. So we can re-use as much as the existing functionality of |
If you want to parse an expression as
|
Not sure i'm following -- what is |
My impression is that you want |
Ok. I thought about that too, it could be useful. But for P = @ivp x' = -x, x(0) ∈ Interval(-1.0, 1.0) which would re-use the We can try to make this work in a later stage: S = @system x' = x
P = @ivp S, x(0) ∈ Interval(-1.0, 1.0) or even S = @system x' = x
X0 = Interval(-1.0, 1.0)
P = @ivp S, X0 |
I was not talking about the system being a variable. This is just the pattern matching when you break up your expression into subexpressions, which I assumed you would want to do in order to find the subexpression that you call |
The problem is resolved by using the pattern |
How should the macro look at the end?
If this is the wanted representation of the However, if you would like to have something like |
I think that Also, i prefer to not restrict the macros too much (at least on this initial stage, and then we see what use arises). |
Here is something to start with (I am not experienced with this stuff): macro ivp(expr)
parsed = Meta.parse(string(expr))
@capture(parsed, (system_, x0_(0) ∈ X0_))
end This only works with the second version ( |
So I am still not sure, if I get it right. But one version would be using MathematicalSystems
using MacroTools
sys = @system(x⁺ = ones(2,2)x)
x0 = [1,2]
macro ivp(expr...)
return esc(Expr(:call, IVP, eval(expr[1]), eval(expr[2])))
end
@ivp sys, x0 #IVP(sys,x0) But this is basically the same as
From my experience, it's sometimes really hard to get your head around macros so for me, it's often a lot of trial and error. You can leave out the macro ivp(expr)
@capture(parsed, (system_, x0_(0) ∈ X0_))
end because This code could then be used to write the macro as macro ivp(expr)
@capture(expr, (system_, x0_(0) ∈ X0_))
return esc(Expr(:call, IVP, eval(system), eval(X0)))
end
@ivp sys, x(0) ∈ 3 # IVP(sys, 3) |
Thanks for having a look into this feature. Our first version is concerned with #137 (comment) and i added a test in the branch #147. |
I'd like to ask for clarification on how the macro should look like because this defines the complexity of the implementation siginifcantly. The first version would be: S = @system x' = x
P = @ivp S, x(0) ∈ Interval(-1.0, 1.0)
# or
P = @ivp S, Interval(-1.0, 1.0) this is the easist implementation and totally independent of The second version would be P = @ivp x' = -x, x(0) ∈ Interval(-1.0, 1.0) but without changing the and the third version would be P = @ivp x' = -x, x(0) ∈ Interval(-1.0, 1.0) but also changing the After considering the option, I prefer the first version. We could theoretically still have the option to add an initial state option to the Also, the second and the third version become quite unpractical for more invovled system definitions, consider e.g. @ivp x' = rand(2,2)*x+rand(2,1)*u + w, w∈W, x∈X, u∈U, x(0) ∈ Interval(-1.0, 1.0) compared to sys = @system x' = rand(2,2)*x+rand(2,1)*u + w, w∈W, x∈X, u∈U,
ivp = @ivp sys, x(0) ∈ Interval(-1.0, 1.0) |
The behavior of a new On the other hand, i like to allow Yes, there's some redundancy in having these 2 ways macros. But i think that is not bad, at least in this preliminary phase. In either case, i didn't think about the implementation yet, but extending the |
Proposal: add
@ivp
for initial-value problem, that behaves like@system
but additionally receives the initial condition, eg.The text was updated successfully, but these errors were encountered: