Ejemplo n.º 1
0
 public EulerODESolver()
 {
     _equations    = new EquationData[3];
     _equations[0] = new EquationData(
         (x, y) => x * x - 2 * y,
         (x0, y0) => x =>
     {
         double c = Math.Exp(2 * x0) * (y0 - 0.5 * x0 * x0 + 0.5 * x0 - 0.25);
         return(c * Math.Exp(-2 * x) + 0.5 * x * x - 0.5 * x + 0.25);
     }
         );
     _equations[1] = new EquationData(
         (x, y) => y * Math.Sin(x) / 6,
         (x0, y0) => x =>
     {
         double c = y0 * Math.Exp(Math.Cos(x0) / 6);
         return(c * Math.Exp(-Math.Cos(x) / 6));
     }
         );
     _equations[2] = new EquationData(
         (x, y) => y * Math.Exp(-x),
         (x0, y0) => x =>
     {
         double c = y0 * Math.Exp(Math.Exp(-x0));
         return(c * Math.Exp(-Math.Exp(-x)));
     }
         );
     this.Spl = new CubicSpline();
     InitializeComponent();
 }
    // Start is called before the first frame update
    void Start()
    {
        // get data from dataController
        dataController = FindObjectOfType <DataController>();
        level          = dataController.GetDifficulty();
        isTutorial     = dataController.GetCurrentTut();
        equation       = dataController.GetCurrentEquationData(level, isTutorial);
        inputTimer     = 0;
        won            = false;

        if (isTutorial)
        {
            levelText.text = "Tutorial " + level.ToString();
        }
        else
        {
            levelText.text = "Stage " + level.ToString();
        }

        currentlyDragging = false;
        roundActive       = true;

        // set up seesaw according to equation
        SetUpSeesaw();
        numInitialBrackets = 0;
    }
Ejemplo n.º 3
0
 //Used to check if a node is unique (A or B) or if it is referenced elsewhere in the tree
 private bool CheckDuplicateNode(Node nodeToCheck, int thisKey)
 {
     foreach (KeyValuePair <int, List <Node> > nodeTrees in equationGroups)
     {
         for (int i = 0; i < nodeTrees.Value.Count; i++)
         {
             if (nodeToCheck.GetIndex() == nodeTrees.Value[i].GetIndex())
             {
                 int          key         = nodeTrees.Key;
                 EquationData updatedData = new EquationData(equation[key][i].symbol, equation[key][i].index);
                 updatedData.jumpToIndex = thisKey;
                 equation[key][i]        = updatedData;
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
    //Sorts the Expression trees into usable equation groups where a root node (parent) and it's children (if any) are sorted into a group to later be
    //  built into an equation for evaluation
    private void GetEquationGroups(Node rootNode)
    {
        Node                thisNode     = rootNode;
        List <Node>         nodeData     = new List <Node>();
        List <EquationData> equationData = new List <EquationData>();
        int keys = equation.Keys.Count;

        //Make sure that the node has children. If it is an element ignore it to prevent adding it twice
        //Alternatively, if it is the root/first node in the tree add it anyway
        if (thisNode.GetChildCount() > 0 || thisNode.GetIndex() == 0)
        {
            //Add a new entry into the dictionary and start populating the 'nodeData' list with this current node
            equationGroups.Add(keys, new List <Node>());
            equation.Add(keys, new List <EquationData>());
            nodeData.Add(thisNode);
            EquationData rootData = new EquationData(thisNode.GetValue(), thisNode.GetIndex());
            //Check if this root node has been used elsewhere
            equationData.Add(rootData);

            //Check if has been used elsewhere, if so set a reference to the dictionary key
            CheckDuplicateNode(thisNode, keys);

            //For each child node, add it to the nodeDataList
            for (int i = 0; i < thisNode.GetChildCount(); i++)
            {
                List <Node> childNode = thisNode.GetChildNodes();
                nodeData.Add(childNode[i]);
                equationData.Add(new EquationData(childNode[i].GetValue(), childNode[i].GetIndex()));
            }
            //Set the value of dictionary of this grouping
            equationGroups[keys] = nodeData;
            equation[keys]       = equationData;

            //Iterate through each childNode and repeat this process
            for (int i = 0; i < thisNode.GetChildCount(); i++)
            {
                List <Node> childNodes = thisNode.GetChildNodes();
                Node        newNode    = childNodes[i];
                GetEquationGroups(newNode);
            }
        }
    }
        private Matrix GetInputMatrix()
        {
            var m = new Matrix(_equations, _equations + 1);

            var children = EquationData.FindChildren <TextBox>();

            foreach (var child in children)
            {
                int col = Grid.GetColumn(child);
                int row = Grid.GetRow(child) - 1;
                if (col > _equations)
                {
                    col -= 1;
                }
                double val = Convert.ToDouble(child.Text);
                m[row, col] = val;
            }

            return(m);
        }
Ejemplo n.º 6
0
        public async Task Add(EquationData equationData)
        {
            await _context.EquationData.AddAsync(equationData);

            await _context.SaveChangesAsync();
        }