# How do you calculate Carnot engine efficiency? (JavaScript)

**Short answer:** the efficiency of a Carnot engine is `eta = 1 - Tc / Th`, with both temperatures in kelvin. An engine working between 500 K and 300 K can convert at most 40 percent of the heat it takes in into work, whatever the working substance.

## What is a Carnot engine?

A Carnot engine is an ideal reversible heat engine that takes heat `Qh` from a hot reservoir at `Th`, does work `W`, and gives the rest `Qc` to a cold reservoir at `Tc`. It runs on two isothermal and two adiabatic steps. No real engine working between the same two temperatures can be more efficient.

## What is the formula?

- Efficiency: `eta = W / Qh = 1 - Qc / Qh`
- For the Carnot cycle: `Qc / Qh = Tc / Th`, so `eta = 1 - Tc / Th`

The temperatures must be in kelvin: K = degrees Celsius + 273.

## How do you calculate it in JavaScript?

```js
const kelvin = (c) => c + 273;

export const carnotEfficiency = (hotK, coldK) => 1 - coldK / hotK;

export function carnot(hotK, coldK, heatIn) {
  const eta = carnotEfficiency(hotK, coldK);
  return { eta, work: eta * heatIn, heatRejected: heatIn * (1 - eta) };
}
```

| Th | Tc | Efficiency | Work for 1000 J in | Heat rejected |
|---|---|---|---|---|
| 500 K | 300 K | 40% | 400 J | 600 J |
| 600 K | 300 K | 50% | 500 J | 500 J |

Between 227 degrees Celsius and 27 degrees Celsius the temperatures are 500 K and 300 K, so the first row is `carnot(kelvin(227), kelvin(27), 1000)`.

## Can an engine be 100 percent efficient?

Only if `Tc` were absolute zero, which is impossible. This is the second law of thermodynamics in numbers: some heat must always be rejected. A claim of 60 percent efficiency between 500 K and 300 K breaks the Carnot limit of 40 percent and cannot be true.

## How can you raise the efficiency?

- Raise the hot temperature `Th`.
- Lower the cold temperature `Tc`.

Raising `Th` from 500 K to 600 K lifts the limit from 40 to 50 percent.

## Frequently asked questions

### Why must temperatures be in kelvin?

The ratio `Tc / Th` comes from the absolute scale. With Celsius values the ratio is meaningless.

### Does the working gas matter?

No. The Carnot efficiency depends only on the two reservoir temperatures.

### Is a real engine as efficient as a Carnot engine?

No. Friction, heat loss and irreversible steps make real engines less efficient.

### What is a refrigerator in this picture?

A Carnot engine run backwards. Its coefficient of performance is `Tc / (Th - Tc)`.

## Try it in a virtual lab

In the [Carnot engine lab on PractiSci](https://www.practisci.in/labs/11-11-carnot-engine) you run the cycle on a p-V diagram and see the work and heat flows. The [thermodynamics chapter guide](https://www.practisci.in/topics/thermodynamics) has the laws, processes and engine formulas for Class 11.

