---
url: /dyad/stable/stdlib/ElectricalComponents/components/Analog.Basic.VariableCapacitor.md
description: >-
  Dyad Analog.Basic.VariableCapacitor docs.  Ideal linear electrical capacitor
  with variable capacitance.
---

# `Analog.Basic.VariableCapacitor` {#Analog.Basic.VariableCapacitor}

Ideal linear electrical capacitor with variable capacitance.

The capacitance value `C` is provided as an external input signal. A lower bound `Cmin` prevents the effective capacitance from reaching zero, which would cause a variable index change:

$$Q = \max(C, C\_{min}) \cdot v$$

The branch current follows from the time derivative of charge:

$$i = \frac{dQ}{dt}$$

This charge-based formulation correctly accounts for time-varying capacitance, producing `i = C \dot{v} + \dot{C} v`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableCapacitor`.

This component extends from [`ElectricalComponents.Analog.Interfaces.OnePort`](../types/Analog.Interfaces.OnePort.md)

## Usage {#Usage}

`ElectricalComponents.Analog.Basic.VariableCapacitor(Cmin=1e-16)`

## Parameters: {#Parameters:}

|   Name |                          Description | Units | Default value |
| ------:| ------------------------------------:| -----:| -------------:|
| `Cmin` | Lower bound for variable capacitance |     F |         1e-16 |

## Connectors {#Connectors}

* `p` - This connector represents an electrical pin with voltage and current as the potential and flow variables, respectively. ([`Pin`](/stdlib/Dyad/connectors/Pin#Pin))

* `n` - This connector represents an electrical pin with voltage and current as the potential and flow variables, respectively. ([`Pin`](/stdlib/Dyad/connectors/Pin#Pin))

* `C` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

## Variables {#Variables}

| Name |                                                  Description | Units |
| ----:| ------------------------------------------------------------:| -----:|
|  `v` |      Voltage across the component (between pin p and pin n). |     V |
|  `i` | Current flowing through the component (from pin p to pin n). |     A |
|  `Q` |                      Electric charge stored in the capacitor |     C |

## Behavior {#Behavior}

$$ \begin{align}
v\left( t \right) &=  - \mathtt{n.v}\left( t \right) + \mathtt{p.v}\left( t \right) \\
i\left( t \right) &= \mathtt{p.i}\left( t \right) \\
\mathtt{n.i}\left( t \right) + \mathtt{p.i}\left( t \right) &= 0 \\
Q\left( t \right) &= max\left( C\left( t \right), \mathtt{Cmin} \right) ~ v\left( t \right) \\
i\left( t \right) &= \frac{\mathrm{d}Q\left( t \right)}{\mathrm{d}t}
\end{align}
$$

## Source {#Source}

````dyad
"""
Ideal linear electrical capacitor with variable capacitance.

The capacitance value `C` is provided as an external input signal.
A lower bound `Cmin` prevents the effective capacitance from reaching
zero, which would cause a variable index change:
```math
Q = \max(C, C_{min}) \cdot v
```
The branch current follows from the time derivative of charge:
```math
i = \frac{dQ}{dt}
```
This charge-based formulation correctly accounts for time-varying
capacitance, producing `i = C \dot{v} + \dot{C} v`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableCapacitor`.
"""
component VariableCapacitor
  extends ElectricalComponents.Analog.Interfaces.OnePort
  "Capacitance input signal"
  C = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Lower bound for variable capacitance"
  parameter Cmin::Capacitance = 1e-16
  "Electric charge stored in the capacitor"
  variable Q::ElectricCharge
relations
  assert(C >= 0, "Capacitance C has to be >= 0!")
  Q = max(C, Cmin) * v
  i = der(Q)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 845, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Capacitor.svg"}
  }
}
end
````

````dyad
"""
Ideal linear electrical capacitor with variable capacitance.

The capacitance value `C` is provided as an external input signal.
A lower bound `Cmin` prevents the effective capacitance from reaching
zero, which would cause a variable index change:
```math
Q = \max(C, C_{min}) \cdot v
```
The branch current follows from the time derivative of charge:
```math
i = \frac{dQ}{dt}
```
This charge-based formulation correctly accounts for time-varying
capacitance, producing `i = C \dot{v} + \dot{C} v`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableCapacitor`.
"""
component VariableCapacitor
  "Positive electrical pin."
  p = Pin() {
    "Dyad": {
      "placement": {"icon": {"iconName": "pos", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }
  "Negative electrical pin."
  n = Pin() {
    "Dyad": {
      "placement": {"icon": {"iconName": "neg", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }
  "Voltage across the component (between pin p and pin n)."
  variable v::Voltage
  "Current flowing through the component (from pin p to pin n)."
  variable i::Current
  "Capacitance input signal"
  C = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Lower bound for variable capacitance"
  parameter Cmin::Capacitance = 1e-16
  "Electric charge stored in the capacitor"
  variable Q::ElectricCharge
relations
  v = p.v - n.v
  i = p.i
  p.i + n.i = 0
  assert(C >= 0, "Capacitance C has to be >= 0!")
  Q = max(C, Cmin) * v
  i = der(Q)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 845, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Capacitor.svg"}
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Ground`](Analog.Basic.VariableCapacitor.md)

  * [`Ramp`](Analog.Basic.VariableCapacitor.md)

  * [`Resistor`](Analog.Basic.VariableCapacitor.md)

  * [`Sine`](Analog.Basic.VariableCapacitor.md)

  * [`VariableCapacitor`](Analog.Basic.VariableCapacitor.md)

  * [`VariableCapacitor`](Analog.Basic.VariableCapacitor.md)

  * [`VoltageSource`](Analog.Basic.VariableCapacitor.md)
