Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/src/basics/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ The basic purely symbolic continuous event interface to encode *one* continuous
event is

```julia
AbstractSystem(eqs, ...; continuous_events::Vector{Equation})
AbstractSystem(eqs, ...; continuous_events::Pair{Vector{Equation}, Vector{Equation}})
AbstractSystem(eqs, _...; continuous_events::Vector{Equation})
AbstractSystem(eqs, _...; continuous_events::Pair{Vector{Equation}, Vector{Equation}})
```

In the former, equations that evaluate to 0 will represent conditions that should
Expand Down Expand Up @@ -272,7 +272,7 @@ In addition to continuous events, discrete events are also supported. The
general interface to represent a collection of discrete events is

```julia
AbstractSystem(eqs, ...; discrete_events = [condition1 => affect1, condition2 => affect2])
AbstractSystem(eqs, _...; discrete_events = [condition1 => affect1, condition2 => affect2])
```

where conditions are symbolic expressions that should evaluate to `true` when an
Expand Down Expand Up @@ -497,7 +497,8 @@ so far we aren't using anything that's not possible with the implicit interface.
You can also write

```julia
[temp ~ furnace_off_threshold] => ModelingToolkit.ImperativeAffect(modified = (;
[temp ~
furnace_off_threshold] => ModelingToolkit.ImperativeAffect(modified = (;
furnace_on)) do x, o, i, c
@set! x.furnace_on = false
end
Expand Down
2 changes: 1 addition & 1 deletion docs/src/basics/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The same principle applies to any parameter type that is not `Float64`.
@parameters p1::Int # integer-valued
@parameters p2::Bool # boolean-valued
@parameters p3::MyCustomStructType # non-numeric
@parameters p4::ComponentArray{...} # non-standard array
@parameters p4::ComponentArray{_...} # non-standard array
```

## Getting the index for a symbol
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/linear_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This is signified by the name being the middle argument to `connect`.
Of the above mentioned functions, all except for [`open_loop`](@ref) return the output of [`ModelingToolkit.linearize`](@ref), which is

```julia
matrices, simplified_sys = linearize(...)
matrices, simplified_sys = linearize(_...)
# matrices = (; A, B, C, D)
```

Expand Down
32 changes: 17 additions & 15 deletions src/systems/diffeqs/basic_transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,25 @@ new_sol = solve(new_prob, Tsit5())

"""
function change_of_variables(
sys::System, iv, forward_subs, backward_subs;
simplify=true, t0=missing, isSDE=false
sys::System, iv, forward_subs, backward_subs;
simplify = true, t0 = missing, isSDE = false
)
t = iv

old_vars = first.(backward_subs)
new_vars = last.(forward_subs)

# use: f = Y(t, X)
# use: dY = (∂f/∂t + μ∂f/∂x + (1/2)*σ^2*∂2f/∂x2)dt + σ∂f/∂xdW
old_eqs = equations(sys)
neqs = get_noise_eqs(sys)
brownvars = brownians(sys)



if neqs === nothing && length(brownvars) === 0
neqs = ones(1, length(old_eqs))
elseif neqs !== nothing
isSDE = true
neqs = [neqs[i,:] for i in 1:size(neqs,1)]
neqs = [neqs[i, :] for i in 1:size(neqs, 1)]

brownvars = map([Symbol(:B, :_, i) for i in 1:length(neqs[1])]) do name
unwrap(only(@brownians $name))
Expand All @@ -135,9 +134,10 @@ function change_of_variables(
end

# df/dt = ∂f/∂x dx/dt + ∂f/∂t
dfdt = Symbolics.derivative( first.(forward_subs), t )
∂f∂x = [Symbolics.derivative( first(f_sub), old_var ) for (f_sub, old_var) in zip(forward_subs, old_vars)]
∂2f∂x2 = Symbolics.derivative.( ∂f∂x, old_vars )
dfdt = Symbolics.derivative(first.(forward_subs), t)
∂f∂x = [Symbolics.derivative(first(f_sub), old_var)
for (f_sub, old_var) in zip(forward_subs, old_vars)]
∂2f∂x2 = Symbolics.derivative.(∂f∂x, old_vars)
new_eqs = Equation[]

for (new_var, ex, first, second) in zip(new_vars, dfdt, ∂f∂x, ∂2f∂x2)
Expand All @@ -154,7 +154,7 @@ function change_of_variables(
ex = substitute(ex, Dict(forward_subs))
ex = substitute(ex, Dict(backward_subs))
if simplify
ex = Symbolics.simplify(ex, expand=true)
ex = Symbolics.simplify(ex, expand = true)
end
push!(new_eqs, Differential(t)(new_var) ~ ex)
end
Expand All @@ -174,10 +174,11 @@ function change_of_variables(
end
end

@named new_sys = System(vcat(new_eqs, first.(backward_subs) .~ last.(backward_subs)), t;
defaults=new_defs,
observed=observed(sys)
)
@named new_sys = System(
vcat(new_eqs, first.(backward_subs) .~ last.(backward_subs)), t;
defaults = new_defs,
observed = observed(sys)
)
if simplify
return mtkcompile(new_sys)
end
Expand Down Expand Up @@ -570,7 +571,8 @@ All accumulation variables have a default of zero.
function add_accumulations(sys::System, vars::Vector{<:Pair})
eqs = get_eqs(sys)
avars = map(first, vars)
if (ints = intersect(avars, unknowns(sys)); !isempty(ints))
ints = intersect(avars, unknowns(sys))
if !isempty(ints)
error("$ints already exist in the system!")
end
D = Differential(get_iv(sys))
Expand Down
Loading
Loading