-
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 function to return gradient of continuous system #160
Comments
What would be the signature of these methods, i mean in terms of the inputs/outputs? About the name, I think that |
I am not sure, if I understand. function vector_field(sys::LinearContinuousSystem, x, u)
return state_matrix(sys)*x + input_matrix(sys)*u
end |
To clarify my previous comment, what i had in mind was the distinction between the field and the function-like behavior (ie. the field applied to a given point / tuple). As it turns out in applications having the field is needed (eg. for what you asked here, we can just wrap the field and pass it to a solver). Here is a proposal: using Revise, MathematicalSystems, LazySets
MathematicalSystems.system(sys::AbstractSystem) = sys
MathematicalSystems.system(sys::InitialValueProblem) = sys.s
struct VectorField{T}
field::T
end
# function-like evaluation
@inline function (V::VectorField)(args...)
evaluate(V, args...)
end
function evaluate(V::VectorField, args...)
return V.field(args...)
end
function VectorField(sys::AbstractSystem)
sys = system(sys)
if islinear(sys)
if inputdim(sys) == 0
field = (x) -> state_matrix(sys) * x
else
field = (x, u) -> state_matrix(sys) * x + input_matrix(sys) * u
end
elseif isaffine(sys)
if inputdim(sys) == 0
field = (x) -> state_matrix(sys) * x + affine_term(sys)
else
field = (x, u) -> state_matrix(sys) * x + affine_term(sys) + input_matrix(sys) * u
end
else
error("the vector field for a system of type $sys is not implemented yet")
end
return VectorField(field)
end
function vector_field(sys::AbstractSystem, args...)
return evaluate(VectorField(sys), args...)
end To be used as: julia> V = VectorField(@system(x' = x));
julia> V([0.0]), V([1.0])
([0.0], [1.0])
julia> V = VectorField(@system(x' = 2x + 1));
julia> V([0.0]), V([1.0])
([1.0], [3.0])
julia> vector_field(@system(x' = x), [0.0])
1-element Array{Float64,1}:
0.0 |
I implemented another way to get the same result. MathematicalSystems.jl/src/successor.jl Lines 215 to 237 in 0bbe3df
As a result, the |
In the same branch, I also propose a more generic way to generate the |
ok, i see, and sorry for my late reply.. i was too busy the last couple of days :/ i checked the branch you propose, thanks! do you mind making to follow up with a pull request?
i find it useful to define
not sure that i follow, why do you mention performance? can you elaborate?
i don't know, but i think that but apart from some comments,eg. do not assume that what is neither linear or affine has a field |
No worries, same here :)
I assumed that adding the additional logic for distinguishing between the cases will increase the runtime compared to just defining
I used
What about defining a getter for the functional fields, e.g. |
As mentioned in this post by @schillic in #96 (comment)
I suggest adding a functionality corresponding to the discrete
successor
method for continuous systems. Possible names are:derivative
tangent
gradient
vectorfield
The text was updated successfully, but these errors were encountered: