Skip to content

Commit 6fef5bc

Browse files
committed
docs: add comprehensive documentation for EvalAt operator
- Document the purpose and behavior of EvalAt - Clarify that t parameter is absolute time (not relative) - Confirm autodifferentiability support with examples - Add usage examples including optimization constraints - Document error conditions Fixes #3849 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 94b5775 commit 6fef5bc

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/variables.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,63 @@ getshift(x::Symbolic) = Symbolics.getmetadata(x, VariableShift, 0)
578578
###################
579579
### Evaluate at ###
580580
###################
581+
"""
582+
EvalAt(t)
583+
584+
An operator that evaluates time-dependent variables at a specific absolute time point `t`.
585+
586+
# Fields
587+
- `t::Union{Symbolic, Number}`: The absolute time at which to evaluate the variable.
588+
589+
# Description
590+
`EvalAt` is used to evaluate time-dependent variables at a specific time point. This is particularly
591+
useful in optimization problems where you need to specify constraints or costs at particular moments
592+
in time.
593+
594+
The operator works by replacing the time argument of time-dependent variables with the specified
595+
time `t`. For variables that don't depend on time, `EvalAt` returns them unchanged.
596+
597+
# Behavior
598+
- For time-dependent variables like `x(t)`, `EvalAt(τ)(x)` returns `x(τ)`
599+
- For time-independent parameters, `EvalAt` returns them unchanged
600+
- For derivatives, `EvalAt` evaluates the derivative at the specified time
601+
- For arrays of variables, `EvalAt` is applied element-wise
602+
603+
# Autodifferentiability
604+
`EvalAt` supports automatic differentiation when applied to differentiable expressions. The operator
605+
properly handles `Differential` operations, making it compatible with ModelingToolkit's symbolic
606+
differentiation system.
607+
608+
# Examples
609+
```julia
610+
using ModelingToolkit
611+
612+
@variables t x(t) y(t)
613+
@parameters p
614+
615+
# Evaluate x at time t=1.0
616+
EvalAt(1.0)(x) # Returns x(1.0)
617+
618+
# Works with parameters (returns unchanged)
619+
EvalAt(1.0)(p) # Returns p
620+
621+
# Works with derivatives
622+
D = Differential(t)
623+
EvalAt(1.0)(D(x)) # Returns D(x) evaluated at t=1.0
624+
625+
# Use in optimization constraints
626+
@optimization_model model begin
627+
@constraints begin
628+
EvalAt(0.5)(x) ~ 2.0 # x must equal 2.0 at t=0.5
629+
end
630+
end
631+
```
632+
633+
# Errors
634+
- Throws an error when applied to variables with more than one argument (e.g., `z(u, t)`)
635+
636+
See also: [`Differential`](@ref)
637+
"""
581638
struct EvalAt <: Symbolics.Operator
582639
t::Union{Symbolic, Number}
583640
end

0 commit comments

Comments
 (0)