Esempio n. 1
0
        static public Tuple<List<TaylorStructure>, List<TaylorStructure>> GetExpansionStruct(AST f, string[] variables, int maxOrder)
        {
            TaylorStructure[] result = new TaylorStructure[MaxIndex(variables.Length, maxOrder+1) + 1];
            Queue<TaylorStructure> queue = new Queue<TaylorStructure>();

            Log.Debug.WriteLine("Original ODE: F = {0}", f);

            TaylorStructure ts = new TaylorStructure();
            ts.degrees = new int[variables.Length];
            ts.func = f;
            ts.order = 0;
            ts.coeff = 1;
            queue.Enqueue(ts);
            while (queue.Count > 0)
            {
                TaylorStructure e = queue.Dequeue();
                int idx = GetIndex(e.degrees, maxOrder);
                result[idx] = e;
                Log.Debug.WriteLine("dF / {0} = {1}", GetEquation(e.degrees, variables), e.func);
                
                if (e.order == maxOrder)
                    continue;
                for (int i = 0; i < variables.Length; ++i)
                {
                    TaylorStructure next = new TaylorStructure();
                    next.degrees = (int[])e.degrees.Clone();
                    next.degrees[i]++;
                    int nextidx = GetIndex(next.degrees, maxOrder);
                    if (result[nextidx] != null) continue; // already calculated
                    next.order = e.order + 1;
                    next.coeff = 1;
                    foreach (var d in next.degrees)
                        next.coeff *= fact(d);
                    next.func = e.func.GetDerivative(variables[i]).Simplify();                    
                    queue.Enqueue(next);
                }
            }
            Log.Debug.Flush();

            List<TaylorStructure> res = new List<TaylorStructure>();
            List<TaylorStructure> error = new List<TaylorStructure>();
            foreach (TaylorStructure e in result)
                if (e != null)
                {
                    if (e.order <= maxOrder)
                        res.Add(e);
                    else
                        error.Add(e);
                }
            return Tuple.Create(res,error);
        }        
Esempio n. 2
0
 public override AST Substitute(string var, AST term)
 {
     return this;
 }
Esempio n. 3
0
 public SQRT(AST term)
 {
     children = new AST[1];
     children[0] = term;
     type = TYPE.SQRT;
 }
Esempio n. 4
0
 public override AST Substitute(string var, AST term)
 {
     return new SQRT(children[0].Substitute(var, term));
 }
Esempio n. 5
0
 public EXP(AST term)
 {
     children = new AST[1];
     children[0] = term;
     type = TYPE.EXP;
 }
Esempio n. 6
0
 public override AST Substitute(string var, AST term)
 {
     return new POW(children[0].Substitute(var, term), power);
 }
Esempio n. 7
0
 public SIN(AST term)
 {
     children = new AST[1];
     children[0] = term;
     type = TYPE.SIN;
 }
Esempio n. 8
0
 public COS(AST term)
 {
     children = new AST[1];
     children[0] = term;
     type = TYPE.COS;
 }
Esempio n. 9
0
 public NEG(AST term)
 {
     children = new AST[1];
     children[0] = term;
     type = TYPE.NEG;
 }
Esempio n. 10
0
 abstract public AST Substitute(string var, AST term);
Esempio n. 11
0
 public override AST Substitute(string var, AST term)
 {
     return name.Equals(var) ? term : this;
 }
Esempio n. 12
0
 public GT(AST lhs, AST rhs)
 {
     this.type = TYPE.GT;
     this.lhs  = lhs;
     this.rhs  = rhs;
 }
Esempio n. 13
0
 public LT(AST lhs, AST rhs)
 {
     this.type = TYPE.LT;
     this.lhs  = lhs;
     this.rhs  = rhs;
 }
Esempio n. 14
0
 public GE(AST lhs, AST rhs)
 {
     this.type = TYPE.GE;
     this.lhs  = lhs;
     this.rhs  = rhs;
 }
Esempio n. 15
0
 public LE(AST lhs, AST rhs)
 {
     this.type = TYPE.LE;
     this.lhs  = lhs;
     this.rhs  = rhs;
 }