Version: dev

remove_equation

Stable function · Editing

Tier: stable · Kind: function · Topic: Editing

JuliaTypeScriptPythonRustGo
remove_equationremoveEquationremove_equation, remove_equation_from_modelremove_equationnot exported

Note: spelling differs from the §2 rule: python=remove_equation_from_model (expected remove_equation); multiple spellings exported by: python

Julia

remove_equation(model::Model, index::Int64)
remove_equation(model::Model, lhs_pattern::ASTExpr)
remove_equation(model::Model, index::Int) -> Model
remove_equation(model::Model, lhs_pattern::ASTExpr) -> Model

Remove an equation from a model.

Can remove by index (1-based) or by matching the left-hand side expression. Throws EditError if the index is out of bounds or no equation matches the pattern.

Source

Example (rename_variable)

renamed = rename_variable(model, "lambda", "k")
@assert parameters(renamed) == ["k"]
@assert to_ascii(renamed.equations[1]) == "D(N)/Dt = (-k) * N"

# Drop the half_life equation, then the variable it defined.
trimmed = remove_variable(remove_equation(model, 2), "half_life")
@assert unknowns(trimmed) == ["N"]
@assert length(trimmed.equations) == 1

# Editing a variable that does not exist raises an EditError.
try
    rename_variable(model, "nope", "k")
    error("expected an EditError")
catch e
    @assert e isa EditError
end

From docs/api/examples/julia/editing.jl

TypeScript

function removeEquation(model: Model, indexOrLhs: number | Expr): Model

Remove an equation from a model

Parameters

  • model — Model to remove equation from
  • indexOrLhs — Either the numeric index or the LHS expression of the equation

Returns

New model with equation removed

Throws

  • EntityNotFoundError if equation not found

Source

Python

Exported as remove_equation and remove_equation_from_model. Both names refer to the same operation.

remove_equation

remove_equation(model: Model, index: int, validate_after_edit: bool = True) -> EditResult

Remove an equation from a model by index.

Source

remove_equation_from_model

remove_equation_from_model(model: Model, index: int, validate_after_edit: bool = True) -> EditResult

Deprecated alias for remove_equation . Remove an equation from a model by index.

Source

Rust

pub fn remove_equation(model: &Model, index: usize) -> EditResult<Model>

Remove an equation from a model by index

Arguments

  • model - The model to modify
  • index - Index of the equation to remove

Returns

  • EditResult<Model> - New model without the equation

Source · Rust docs

Go

Go does not export this function.