---
url: /dyad/stable/stdlib/ElectricalComponents/components/Analog.Basic.VariableResistor.md
description: >-
  Dyad Analog.Basic.VariableResistor docs.  Ideal linear electrical resistor
  with variable resistance.
---

# `Analog.Basic.VariableResistor` {#Analog.Basic.VariableResistor}

Ideal linear electrical resistor with variable resistance.

The resistance value `R` is provided as an external input signal. An optional linear temperature coefficient `alpha` adjusts the actual resistance based on the heat port temperature:

$$R\_{actual} = R \cdot (1 + \alpha \cdot (T\_{heatPort} - T\_{ref}))$$

The electrical behavior follows Ohm's law:

$$v = R\_{actual} \cdot i$$

Power dissipated in the resistor is transferred as heat through the thermal port `heat_port`.

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

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

## Usage {#Usage}

`ElectricalComponents.Analog.Basic.VariableResistor(T_ref=300.15, alpha=0.0)`

## Parameters: {#Parameters:}

|    Name |                                  Description | Units | Default value |
| -------:| --------------------------------------------:| -----:| -------------:|
| `T_ref` |                        Reference temperature |     K |        300.15 |
| `alpha` | Linear temperature coefficient of resistance |   1/K |           0.0 |

## 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))

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

* `heat_port` - This connector represents a thermal port with temperature and heat flow as the potential and flow variables, respectively. ([`HeatPort`](/stdlib/Dyad/connectors/HeatPort#HeatPort))

## 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 |
|  `R_actual` |                 Actual resistance accounting for temperature |     Ω |
| `LossPower` |                             Power dissipated in the resistor |     W |

## 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 \\
\mathtt{R_actual}\left( t \right) &= R\left( t \right) ~ \left( 1 + \left(  - \mathtt{T_ref} + \mathtt{heat_port.T}\left( t \right) \right) ~ \mathtt{alpha} \right) \\
v\left( t \right) &= \mathtt{R_actual}\left( t \right) ~ i\left( t \right) \\
\mathtt{LossPower}\left( t \right) &= i\left( t \right) ~ v\left( t \right) \\
\mathtt{heat_port.Q_flow}\left( t \right) &=  - \mathtt{LossPower}\left( t \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Ideal linear electrical resistor with variable resistance.

The resistance value `R` is provided as an external input signal.
An optional linear temperature coefficient `alpha` adjusts the
actual resistance based on the heat port temperature:
```math
R_{actual} = R \cdot (1 + \alpha \cdot (T_{heatPort} - T_{ref}))
```
The electrical behavior follows Ohm's law:
```math
v = R_{actual} \cdot i
```
Power dissipated in the resistor is transferred as heat through
the thermal port `heat_port`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableResistor`.
"""
component VariableResistor
  extends ElectricalComponents.Analog.Interfaces.OnePort
  "Resistance input signal"
  R = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Thermal port for heat exchange"
  heat_port = HeatPort() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 460, "y1": 950, "x2": 560, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Reference temperature"
  parameter T_ref::Temperature = 300.15
  "Linear temperature coefficient of resistance"
  parameter alpha::LinearTemperatureCoefficient = 0.0
  "Actual resistance accounting for temperature"
  variable R_actual::Resistance
  "Power dissipated in the resistor"
  variable LossPower::Power
relations
  assert((1 + alpha * (heat_port.T - T_ref)) >= 1e-15, "Temperature outside scope of model!")
  R_actual = R * (1 + alpha * (heat_port.T - T_ref))
  v = R_actual * i
  LossPower = v * i
  heat_port.Q_flow = -LossPower
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 800, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Resistor.svg"}
  }
}
end
````

````dyad
"""
Ideal linear electrical resistor with variable resistance.

The resistance value `R` is provided as an external input signal.
An optional linear temperature coefficient `alpha` adjusts the
actual resistance based on the heat port temperature:
```math
R_{actual} = R \cdot (1 + \alpha \cdot (T_{heatPort} - T_{ref}))
```
The electrical behavior follows Ohm's law:
```math
v = R_{actual} \cdot i
```
Power dissipated in the resistor is transferred as heat through
the thermal port `heat_port`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableResistor`.
"""
component VariableResistor
  "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
  "Resistance input signal"
  R = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Thermal port for heat exchange"
  heat_port = HeatPort() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 460, "y1": 950, "x2": 560, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Reference temperature"
  parameter T_ref::Temperature = 300.15
  "Linear temperature coefficient of resistance"
  parameter alpha::LinearTemperatureCoefficient = 0.0
  "Actual resistance accounting for temperature"
  variable R_actual::Resistance
  "Power dissipated in the resistor"
  variable LossPower::Power
relations
  v = p.v - n.v
  i = p.i
  p.i + n.i = 0
  assert((1 + alpha * (heat_port.T - T_ref)) >= 1e-15, "Temperature outside scope of model!")
  R_actual = R * (1 + alpha * (heat_port.T - T_ref))
  v = R_actual * i
  LossPower = v * i
  heat_port.Q_flow = -LossPower
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 800, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Resistor.svg"}
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
