1function x = Func(typ, n, p) 2% FUNC Func class constructor. 3% x = Func(typ, n, p) 4% A class for functors. 5% A functor is an object that behaves like a function. Cantera 6% defines a set of functors to use to create arbitrary functions to 7% specify things like heat fluxes, piston speeds, etc., in reactor 8% network simulations. Of course, they can be used for other things 9% too. 10% 11% The main feature of a functor class is that it overloads the ``()`` 12% operator to evaluate the function. For example, suppose object 13% ``f`` is a functor that evaluates the polynomial :math:`2x^2 - 3x + 1`. 14% Then writing ``f(2)`` would cause the method that evaluates the 15% function to be invoked, and would pass it the argument ``2``. The 16% return value would of course be 3. 17% 18% The types of functors you can create in Cantera are these: 19% 20% 1. A polynomial 21% 2. A Fourier series 22% 3. A sum of Arrhenius terms 23% 4. A Gaussian. 24% 25% You can also create composite functors by adding, multiplying, or 26% dividing these basic functors, or other composite functors. 27% 28% Note: this MATLAB class shadows the underlying C++ Cantera class 29% "Func1". See the Cantera C++ documentation for more details. 30% 31% See also: :mat:func:`polynom`, :mat:func:`gaussian`, :mat:func:`plus`, 32% :mat:func:`rdivide`, :mat:func:`times` 33% 34% :param typ: 35% String indicating type of functor to create. Possible values are: 36% 37% * ``'polynomial'`` 38% * ``'fourier'`` 39% * ``'gaussian'`` 40% * ``'arrhenius'`` 41% * ``'sum'`` 42% * ``'diff'`` 43% * ``'ratio'`` 44% * ``'composite'`` 45% * ``'periodic'`` 46% 47% :param n: 48% Number of parameters required for the functor 49% :param p: 50% Vector of parameters 51% :return: 52% Instance of class :mat:func:`Func` 53 54if ~isa(typ, 'char') 55 error('Function type must be a string') 56end 57 58x.f1 = 0; 59x.f2 = 0; 60x.coeffs = 0; 61 62itype = -1; 63if strcmp(typ, 'polynomial') 64 itype = 2; 65elseif strcmp(typ, 'fourier') 66 itype = 1; 67elseif strcmp(typ, 'arrhenius') 68 itype = 3; 69elseif strcmp(typ, 'gaussian') 70 itype = 4; 71end 72 73if itype > 0 74 x.coeffs = p; 75 x.index = funcmethods(0, itype, n, p); 76elseif strcmp(typ, 'periodic') 77 itype = 50; 78 x.f1 = n; 79 x.coeffs = p; 80 x.index = funcmethods(0, itype, n.index, p); 81else 82 if strcmp(typ, 'sum') 83 itype = 20; 84 elseif strcmp(typ, 'diff') 85 itype = 25; 86 elseif strcmp(typ, 'prod') 87 itype = 30; 88 elseif strcmp(typ, 'ratio') 89 itype = 40; 90 elseif strcmp(typ, 'composite') 91 itype = 60; 92 end 93 x.f1 = n; 94 x.f2 = p; 95 x.index = funcmethods(0, itype, n.index, p.index); 96end 97 98x.typ = typ; 99x = class(x, 'Func'); 100