> ## Documentation Index
> Fetch the complete documentation index at: https://calcs.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Equation Widget

> Perform calculations and display results in Calcs.com templates

## Widget Core Function

The equation widget is used for doing engineering calculations. It's the primary calculation engine in Calcs.com templates.

### UI Experience

* Not interactive for the user
* Displays the equation used for the calculation
* Shows the calculated value to the user

### Data Organization and Manipulation

Primary widget for:

* Mathematical calculations and algebraic expressions
* Conditional statements and checks
* Iterations and matrix/vector manipulation

<Note>
  Watch tutorials:

  * [Create a Equation Widget](https://www.loom.com/share/b355f3747e484e999dab1bf4b76f282f)
  * [Advanced Equation Widget](https://www.loom.com/share/dba435240f714cf0bc96d84845172ccf)
</Note>

## Equation Structure

### Single Equation

```json theme={null}
{
  "type": "computed",
  "label": "Area",
  "symbol": "A",
  "units": "mm^2",
  "equation": [
    {
      "result": "width * height",
      "condition": "@default"
    }
  ],
  "referenceId": "area"
}
```

### Multiple Conditional Equations

```json theme={null}
{
  "type": "computed",
  "label": "Capacity Factor",
  "symbol": "φ",
  "equation": [
    {
      "result": "0.9",
      "condition": "loadType == 'tension'"
    },
    {
      "result": "0.85",
      "condition": "loadType == 'compression'"
    },
    {
      "result": "0.75",
      "condition": "@default"
    }
  ],
  "referenceId": "phi"
}
```

## Using @ Shortcuts

Simplify equation building by using "@" to reference other widgets:

```json theme={null}
{
  "equation": [
    {
      "result": "@width * @height",
      "condition": "@default"
    }
  ]
}
```

The "@" symbol searches by label, symbol, and reference ID, automatically inserting the correct references.

<Note>
  [Watch tutorial: Using @ in equations](https://www.loom.com/share/be76512fcf4b41d1b5bc124990992ca3)
</Note>

## Error Handling

### ThrowError vs Throw

* **`throwError`**: Displays a specific message to the user
* **`throw`**: Shows generic "Unexpected Error" message

```json theme={null}
{
  "equation": [
    {
      "result": "width / height",
      "condition": "height != 0"
    },
    {
      "result": "throwError('Height cannot be zero')",
      "condition": "@default"
    }
  ]
}
```

## Special "members" Equation Widget

For exporting data to Member Schedule:

```json theme={null}
{
  "type": "computed",
  "label": "Members Export",
  "export": true,
  "hidden": true,
  "equation": [
    {
      "condition": "@default",
      "result": "[
        { 
          id: 'member',
          designation: designation,
          length: L,
          lengthUnit: 'm',
          nCom: N_compression,
          comments: 'Main beam'
        }
      ]"
    }
  ],
  "referenceId": "members"
}
```

## Advanced Features

### Matrix Operations

```json theme={null}
{
  "result": "[[1,2,3], [4,5,6]] * transpose([[7], [8], [9]])"
}
```

### Iterations

```json theme={null}
{
  "result": "sum(iterate(1, 10, 1, i^2, i))"
}
```

### Unit Conversions

```json theme={null}
{
  "result": "convert(length, 'mm', 'm')"
}
```

## Conditional Logic

### Using @default

The `@default` condition acts as an "else" statement:

```json theme={null}
{
  "equation": [
    {
      "result": "value1",
      "condition": "type == 'A'"
    },
    {
      "result": "value2",
      "condition": "type == 'B'"
    },
    {
      "result": "value3",
      "condition": "@default"
    }
  ]
}
```

<Note>
  [Watch tutorial: Using @default](https://www.loom.com/share/4e158da33ce54fa38800fc38bcc3a635)
</Note>

## Best Practices

<Tip>
  * Use meaningful variable names
  * Add comments in authorNotes for complex calculations
  * Include proper error handling
  * Reference relevant standards in the references field
  * Use @default for catch-all conditions
  * Test edge cases thoroughly
</Tip>

## Common Patterns

### Safety Factor Application

```json theme={null}
{
  "result": "phi * capacity",
  "condition": "@default"
}
```

### Min/Max Selection

```json theme={null}
{
  "result": "min(value1, value2, value3)",
  "condition": "@default"
}
```

### Rounding

```json theme={null}
{
  "result": "round(value, 2)",
  "condition": "@default"
}
```

## Examples from Current Calculators

| ReferenceId | Calculator                                                                                                                            |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `s_t-`      | [EU Steel Column](https://calcs.com/organisation/2ad7e5c6-8d23-416d-acb1-5487dc65150a/templates/6d7fc7ed-f6f7-4392-822b-cdee58bab93b) |
