
:html_theme.sidebar_secondary.remove:

.. py:currentmodule:: cantera


.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/matlab/equil.m"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_matlab_equil.m>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_matlab_equil.m:

Methane/air chemical equilibrium
================================


This example computes the adiabatic flame temperature and equilibrium
composition for a methane/air mixture as a function of equivalence ratio.

Requires: cantera >= 3.2.0

.. tags:: Matlab, combustion, equilibrium, plotting

.. GENERATED FROM PYTHON SOURCE LINES 0-11

.. code-block:: Matlab

    function equil(g)
        tic
        help equil

        if nargin == 1
            gas = g;
        else
            gas = ct.Solution('gri30.yaml', 'gri30');
        end

        nsp = gas.nSpecies;

.. GENERATED FROM PYTHON SOURCE LINES 21-22

Find methane, nitrogen, and oxygen indices

.. GENERATED FROM PYTHON SOURCE LINES 23-42

.. code-block:: Matlab
   :dedent: 1

        ich4 = gas.speciesIndex('CH4');
        io2 = gas.speciesIndex('O2');
        in2 = gas.speciesIndex('N2');

        nPhis = 50;
        phi = linspace(0.2, 2.70, nPhis);
        tad(nPhis) = 0;
        xeq(nsp, nPhis) = 0;

        for i = 1:nPhis
            x = zeros(nsp, 1);
            x(ich4, 1) = phi(i);
            x(io2, 1) = 2.0;
            x(in2, 1) = 7.52;
            gas.TPX = {300, 101325, x};
            gas.equilibrate('HP');
            tad(i) = gas.T;
            xeq(:, i) = gas.X;
        end

.. GENERATED FROM PYTHON SOURCE LINES 43-44

Plot results

.. GENERATED FROM PYTHON SOURCE LINES 44-72

.. code-block:: Matlab

        clf;
        subplot(1, 2, 1);
        plot(phi, tad);
        xlabel('Equivalence Ratio');
        ylabel('Temperature (K)');
        title('Adiabatic Flame Temperature');

        subplot(1, 2, 2);
        semilogy(phi, xeq);
        axis([phi(1), phi(50), 1.0e-14, 1]);
        %legend(speciesName(gas,1:nsp),1);
        j = 10;

        for k = 1:nsp
            text(phi(j), 1.5 * xeq(k, j), gas.speciesName(k))
            j = j + 2;

            if j > 46
                j = 10;
            end

        end

        xlabel('Equivalence Ratio');
        ylabel('Mole Fraction');
        title('Equilibrium Composition');

        toc
    end

.. _sphx_glr_download_examples_matlab_equil.m:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Matlab source code: equil.m <equil.m>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: equil.zip <equil.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
