# How Torque varies with Air to Fuel Ratio

For my Stellaris Launchpad engine simulator, I wished to add a calculation of the Air to Fuel Ratio (AFR) or lambda/equivalence ratio for the current engine conditions. I did this crudely by using the throttle position, engine speed (this->s) and current fuel pulse width (this->F) as factors in calculating the AFR:

`this->AFR = (0.32666 * this->s * this->throttle)/(this->F);`

The equivalence ratio, or lambda (inverse of each other) can then be calculated from the AFR and the stoichiometric ratio which for gasoline is 14.7 units of air to 1 unit of fuel:

`this->equiv = this->AFR/14.7;`

Then I was interested in knowing how the Air to Fuel Ratio affects the maximum Torque output of an engine. In chapter 4 of Introduction to Internal Combustion Engines by Richard Stone the affect of equivalence ratio and ignition timing on BMEP are discussed. I used the figures given here to calculate a rough equation for relating lambda and a torque scale factor (0 to 1). An explanation and some good diagrams are also shown on this website http://www.daytona-sensors.com/tech_tuning.html

And so my scale factor is calculated by

`float scale = -1.1536*pow(this->equiv,2) + 2.6954*this->equiv - 0.5695; // Scale torque for equivalence ratio `

I actually had to restrict the effect of this scaling factor though because at engine start up, the ratios are all wrong which would cause the engine to produce 0 torque and never get going.

```if(scale < 0.7){ scale = 0.7; }```