当前位置: 首页>>代码示例>>C#>>正文


C# FloatMatrix.numCols方法代码示例

本文整理汇总了C#中FloatMatrix.numCols方法的典型用法代码示例。如果您正苦于以下问题:C# FloatMatrix.numCols方法的具体用法?C# FloatMatrix.numCols怎么用?C# FloatMatrix.numCols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FloatMatrix的用法示例。


在下文中一共展示了FloatMatrix.numCols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        Debug.Assert((CCopasiRootContainer.getRoot() != null));
        // create a new datamodel
        CCopasiDataModel dataModel = CCopasiRootContainer.addDatamodel();
        Debug.Assert((dataModel != null));
        Debug.Assert((CCopasiRootContainer.getDatamodelList().size() == 1));
        // next we import a simple SBML model from a string

        // clear the message queue so that we only have error messages from the import in the queue
        CCopasiMessage.clearDeque();
        bool result=true;
        try
        {
          result = dataModel.importSBMLFromString(MODEL_STRING);
        }
        catch
        {
        System.Console.Error.WriteLine("Import of model failed miserably.");
        System.Environment.Exit(1);
        }
        // check if the import was successful
        int mostSevere = CCopasiMessage.getHighestSeverity();
        // if it was a filtered error, we convert it to an unfiltered type
        // the filtered error messages have the same value as the unfiltered, but they
        // have the 7th bit set which basically adds 128 to the value
        mostSevere = mostSevere & 127;

        // we assume that the import succeeded if the return value is true and
        // the most severe error message is not an error or an exception
        if (result != true &&  mostSevere < CCopasiMessage.ERROR)
        {
        System.Console.Error.WriteLine("Sorry. Model could not be imported.");
        System.Environment.Exit(1);
        }

        //
        // now we tell the model object to calculate the jacobian
        //
        CModel model = dataModel.getModel();
        Debug.Assert((model != null));

        if (model != null)
        {
        // running a task, e.g. a trajectory will automatically make sure that
        // the initial values are transferred to the current state before the calculation begins.
        // If we use low level calculation methods like the one to calculate the jacobian, we
        // have to make sure the the initial values are applied to the state
        model.applyInitialValues();
        // we need an array that stores the result
        // the size of the matrix does not really matter because
        // the calculateJacobian autoamtically resizes it to the correct
        // size
        FloatMatrix jacobian=new FloatMatrix();
        // the first parameter to the calculation function is a reference to
        // the matrix where the result is to be stored
        // the second parameter is the derivationFactor for the calculation
        // it basically represents a relative delta value for the calculation of the derivatives
        // the third parameter is a boolean indicating whether the jacobian should
        // be calculated from the reduced (true) or full (false) system
        model.getMathContainer().calculateJacobian(jacobian, 1e-12, false);
        // now we print the result
        // the jacobian stores the values in the order they are
        // given in the user order in the state template so it is not really straight
        // forward to find out which column/row corresponds to which species
        CStateTemplate stateTemplate = model.getStateTemplate();
        // and we need the user order
        SizeTVector userOrder = stateTemplate.getUserOrder();
        // from those two, we can construct an new vector that contains
        // the names of the entities in the jacobian in the order in which they appear in
        // the jacobian
        System.Collections.Generic.List<string> nameVector=new System.Collections.Generic.List<string>();
        CModelEntity entity = null;
        int status;

        for (uint i = 0; i < userOrder.size(); ++i)
        {
            entity = stateTemplate.getEntity(userOrder.get(i));
            Debug.Assert((entity != null));
            // now we need to check if the entity is actually
            // determined by an ODE or a reaction
            status = entity.getStatus();

            if (status == CModelEntity.ODE ||
                    (status == CModelEntity.REACTIONS && entity.isUsed()))
            {
                nameVector.Add(entity.getObjectName());
            }
        }

        Debug.Assert((nameVector.Count == jacobian.numRows()));
        // now we print the matrix, for this we assume that no
        // entity name is longer then 5 character which is a save bet since
        // we know the model
        System.Console.Out.NewLine = "";
        System.Console.WriteLine(System.String.Format("Jacobian Matrix:{0}",System.Environment.NewLine));
        System.Console.WriteLine(System.String.Format("size:{0}x{1}{2}", jacobian.numRows(), jacobian.numCols(), System.Environment.NewLine));
        System.Console.WriteLine(System.String.Format("{0}", System.Environment.NewLine));
        System.Console.Out.WriteLine(System.String.Format("{0,7}"," "));

//.........这里部分代码省略.........
开发者ID:jonasfoe,项目名称:COPASI,代码行数:101,代码来源:example8.cs


注:本文中的FloatMatrix.numCols方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。