Title: | Network of Differential Equations |
---|---|
Description: | Simulates a network of ordinary differential equations of order two. The package provides an easy interface to construct networks. In addition you are able to define different external triggers to manipulate the trajectory. The method is described by Surmann, Ligges, and Weihs (2014) <doi:10.1109/ENERGYCON.2014.6850482>. |
Authors: | Dirk Surmann [aut, cre] |
Maintainer: | Dirk Surmann <[email protected]> |
License: | LGPL-3 |
Version: | 1.3.2 |
Built: | 2024-11-20 04:35:24 UTC |
Source: | https://github.com/surmann/odenetwork |
Calculates the resonance frequencies of a given ODEnetwork
.
The resonance frequencies are calculated without respect to the dampers and neighbourhood structure.
calcResonances(odenet)
calcResonances(odenet)
odenet |
Object of class |
a data frame with a vector of resonance frequencies.
masses <- 1 dampers <- as.matrix(0.1) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) calcResonances(odenet)
masses <- 1 dampers <- as.matrix(0.1) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) calcResonances(odenet)
Converts a given matrix with two rows from polar to cartesian coordinates and vice versa.
convertCoordinates(coords, convertto = "cartesian")
convertCoordinates(coords, convertto = "cartesian")
coords |
[ |
convertto |
[ |
a matrix with converted coordinates
if (interactive()) { coordsK <- rbind(c(3, 0), c(1, 3), c(0, 2), c(-3, 1), c(-1, 0), c(-1, -3), c(0, -2), c(2, -3)) coordsP <- convertCoordinates(coordsK, "polar") }
if (interactive()) { coordsK <- rbind(c(3, 0), c(1, 3), c(0, 2), c(-3, 1), c(-1, 0), c(-1, -3), c(0, -2), c(2, -3)) coordsP <- convertCoordinates(coordsK, "polar") }
Creates functions for constant and linear events of the given ODEnetwork
to know when events have to be replaced or forced.
createEvents(odenet)
createEvents(odenet)
odenet |
[ |
an extended list of class [ODEnetwork
].
if (interactive()) { masses <- 1 dampers <- as.matrix(1.5) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) eventdat <- data.frame( var = c("x.1", "x.1") , time = c(1, 3) , value = c(1, 3) , stringsAsFactors = TRUE ) odenet <- setState(odenet, 0, 0) odenet <- setEvents(odenet, eventdat) createEvents(odenet) }
if (interactive()) { masses <- 1 dampers <- as.matrix(1.5) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) eventdat <- data.frame( var = c("x.1", "x.1") , time = c(1, 3) , value = c(1, 3) , stringsAsFactors = TRUE ) odenet <- setState(odenet, 0, 0) odenet <- setEvents(odenet, eventdat) createEvents(odenet) }
Creates the Jacobian matrix for a special set of parameters of the ODE. The first n columns contain the derivatives with respect to d_ii, followed by the derivatives with respect to k_ii. The last 2*n columns include the derivatives with respect to the states.
createJacobian(odenet, ParamVec = NA)
createJacobian(odenet, ParamVec = NA)
odenet |
[ |
ParamVec |
[ |
the Jacobian matrix of size 2n*4n.
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity) jac <- createJacobian(odenet)
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity) jac <- createJacobian(odenet)
Creates the set of differential equations of order one from the ODEnetwork
.
createOscillators(odenet)
createOscillators(odenet)
odenet |
[ |
a function with a set of differential equations of order one to use in a numerical step
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createOscillators(odenet) }
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createOscillators(odenet) }
Creates a vector with assigned parameters of the given ODEnetwork
.
createParamVec(odenet)
createParamVec(odenet)
odenet |
[ |
a named vector with assigned values
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createParamVec(odenet) }
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createParamVec(odenet) }
Creates a vector with the starting state of the given ODEnetwork
.
createState(odenet)
createState(odenet)
odenet |
[ |
a named vector with assigned starting state
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createState(odenet) }
if (interactive()) { masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) createState(odenet) }
Estimates the distances between the oscillators of a ODEnetwork
from an equilibrium state.
estimateDistances( odenet, equilibrium, distGround = c("combined", "individual", "fixed", c("A", "B", "123", "A")), optim.control = list() )
estimateDistances( odenet, equilibrium, distGround = c("combined", "individual", "fixed", c("A", "B", "123", "A")), optim.control = list() )
odenet |
[ |
equilibrium |
[ |
distGround |
[ |
optim.control |
[ |
an extended list of class ODEnetwork
.
Matrix of distances is added or overwritten.
masses <- c(1, 1) dampers <- diag(c(1, 1)) springs <- diag(c(1, 1)) springs[1, 2] <- 1 equilibrium <- c(1/3, 5/3) odenet <- ODEnetwork(masses, dampers, springs) estimateDistances(odenet, equilibrium)$distances estimateDistances(odenet, equilibrium, distGround="individual")$distances
masses <- c(1, 1) dampers <- diag(c(1, 1)) springs <- diag(c(1, 1)) springs[1, 2] <- 1 equilibrium <- c(1/3, 5/3) odenet <- ODEnetwork(masses, dampers, springs) estimateDistances(odenet, equilibrium)$distances estimateDistances(odenet, equilibrium, distGround="individual")$distances
Getting result from numerical solving algorithm of given ODEnetwork
.
getResult(odenet)
getResult(odenet)
odenet |
[ |
a matrix with columns time and states 1 and 2 of class deSolve
.
masses <- 1 dampers <- as.matrix(0.1) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) getResult(odenet)
masses <- 1 dampers <- as.matrix(0.1) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) getResult(odenet)
Creates a list of class ODEnetwork
.
The coordinate type can be set to cartesian (position and
velocity) or to polar coordinates (angle and magnitude).
ODEnetwork(masses, dampers, springs, cartesian = TRUE, distances = NA)
ODEnetwork(masses, dampers, springs, cartesian = TRUE, distances = NA)
masses |
[ |
dampers |
[ |
springs |
[ |
cartesian |
[ |
distances |
[ |
a list of class [ODEnetwork
].
mM <- c(40, 10, 10) mD <- diag(c(1, 5, 0)) mD[1, 2] <- 1 mD[2, 3] <- 1 mK <- diag(c(50, 50, 0)) mK[1, 2] <- 10 mK[2, 3] <- 10 odenet <- ODEnetwork(mM, mD, mK)
mM <- c(40, 10, 10) mD <- diag(c(1, 5, 0)) mD[1, 2] <- 1 mD[2, 3] <- 1 mK <- diag(c(50, 50, 0)) mK[1, 2] <- 10 mK[2, 3] <- 10 odenet <- ODEnetwork(mM, mD, mK)
Plots the results of simuNetwork
of the given ODEnetwork
in different ways.
## S3 method for class 'ODEnetwork' plot(x, ..., state = "12", var = NULL)
## S3 method for class 'ODEnetwork' plot(x, ..., state = "12", var = NULL)
x |
[ |
... |
Additional arguments. |
state |
[ |
var |
[ |
masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) odenet <- setState(odenet, c(1, 3), c(0, 0)) odenet <- simuNetwork(odenet, seq(0, 10, by = 0.05)) plot(odenet) plot(odenet, var = 2L) plot(odenet, state = "1") plot(odenet, state = "2") plot(odenet, state = "1vs2")
masses <- c(1, 2) dampers <- diag(c(0.1, 0.5)) dampers[1, 2] <- 0.05 springs <- diag(c(4, 10)) springs[1, 2] <- 6 odenet <- ODEnetwork(masses, dampers, springs) odenet <- setState(odenet, c(1, 3), c(0, 0)) odenet <- simuNetwork(odenet, seq(0, 10, by = 0.05)) plot(odenet) plot(odenet, var = 2L) plot(odenet, state = "1") plot(odenet, state = "2") plot(odenet, state = "1vs2")
Sets different types of events for the given ODEnetwork
.
setEvents(odenet, events, type = "dirac")
setEvents(odenet, events, type = "dirac")
odenet |
[ |
events |
[ |
type |
[ |
an extended list of class [ODEnetwork
].
masses <- 1 dampers <- as.matrix(1.5) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) eventdat <- data.frame( var = c("x.1", "x.1") , time = c(1, 3) , value = c(1, 3) , stringsAsFactors = TRUE ) odenet <- setState(odenet, 0, 0) odenet <- setEvents(odenet, eventdat) odenet <- simuNetwork(odenet, seq(0, 10, by = 0.1)) plot(odenet)
masses <- 1 dampers <- as.matrix(1.5) springs <- as.matrix(4) odenet <- ODEnetwork(masses, dampers, springs) eventdat <- data.frame( var = c("x.1", "x.1") , time = c(1, 3) , value = c(1, 3) , stringsAsFactors = TRUE ) odenet <- setState(odenet, 0, 0) odenet <- setEvents(odenet, eventdat) odenet <- simuNetwork(odenet, seq(0, 10, by = 0.1)) plot(odenet)
Sets the starting State for the given ODEnetwork
.
setState(odenet, state1, state2)
setState(odenet, state1, state2)
odenet |
[ |
state1 |
[ |
state2 |
[ |
an extended list of class [ODEnetwork
].
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity)
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity)
Simulates the given ODEnetwork
over a time range.
simuNetwork(odenet, times, origin.min.time = FALSE, ...)
simuNetwork(odenet, times, origin.min.time = FALSE, ...)
odenet |
[ |
times |
[ |
origin.min.time |
[ |
... |
Additional arguments. |
an extended list of class [ODEnetwork
].
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity) odenet <- simuNetwork(odenet = odenet, times = seq(0, 20))
masses <- 4:6 dampers <- diag(1:3) springs <- diag(7:9) odenet <- ODEnetwork(masses, dampers, springs) position <- rep(10, 3) velocity <- rep(0, 3) odenet <- setState(odenet, position, velocity) odenet <- simuNetwork(odenet = odenet, times = seq(0, 20))
Updates the parameters of an existing ODE network. Possible parameters are the oscillator configuration and the starting values. The function overwrites the parameters in the vector and matrices. It will not change the size of the network. It is possible to set a new vector and new matrices, or single parameters in a names vector.
updateOscillators( odenet, ParamVec = NULL, masses = NULL, dampers = NULL, springs = NULL, distances = NULL, state1 = NULL, state2 = NULL )
updateOscillators( odenet, ParamVec = NULL, masses = NULL, dampers = NULL, springs = NULL, distances = NULL, state1 = NULL, state2 = NULL )
odenet |
[ |
ParamVec |
[ |
masses |
[ |
dampers |
[ |
springs |
[ |
distances |
[ |
state1 |
[ |
state2 |
[ |
an extended list of class [ODEnetwork
].
masses <- c(1:5) dampers <- diag(11:15) springs <- diag(21:25) odenet <- ODEnetwork(masses, dampers, springs) odenet <- updateOscillators(odenet, masses = c(3:7)) odenet <- updateOscillators(odenet, c(k.1.2 = 201, k.3.5 = 202, r.1 = 2)) # Warning: Following value is ignored, because it is on the lower triangle odenet <- updateOscillators(odenet, c(d.2.1 = 101))
masses <- c(1:5) dampers <- diag(11:15) springs <- diag(21:25) odenet <- ODEnetwork(masses, dampers, springs) odenet <- updateOscillators(odenet, masses = c(3:7)) odenet <- updateOscillators(odenet, c(k.1.2 = 201, k.3.5 = 202, r.1 = 2)) # Warning: Following value is ignored, because it is on the lower triangle odenet <- updateOscillators(odenet, c(d.2.1 = 101))