Пример #1
0
        public override INumber Multiple(Runtime.RuntimeData runtime, INumber val)
        {
            MultipleFormula mf = new MultipleFormula();

            mf.AddItem(runtime, this);
            mf.AddItem(runtime, val);
            return(mf);
        }
Пример #2
0
        public INumber ExecuteDiff(RuntimeData runtime, string t, INumber[] parameters)
        {
            var res = new FuncedINumber(runtime.Functions["cos"], parameters);

            var vaDiff = parameters[0].ExecuteDiff(runtime, t);

            if (vaDiff.Equals(runtime, Number.New(0)))
            {
                return(res);
            }

            MultipleFormula mf = new MultipleFormula();

            mf.AddItem(runtime, vaDiff);
            mf.AddItem(runtime, res);
            return(mf);
        }
Пример #3
0
        public INumber ExecuteDiff(RuntimeData runtime, string t, INumber[] parameters)
        {
            // log(xy) => log(x) + log(y)
            if (parameters[1] is MultipleFormula)
            {
                AdditionFormula af = new Expression.AdditionFormula();
                foreach (var item in (parameters[1] as MultipleFormula).Items)
                {
                    af.AddItem(runtime, this.ExecuteDiff(runtime, t, new INumber[] { parameters[0], item }));
                }
                return(af);
            }
            if (parameters[1] is Fraction)
            {
                AdditionFormula af = new Expression.AdditionFormula();
                Fraction        f  = parameters[1] as Fraction;
                af.AddItem(runtime, this.ExecuteDiff(runtime, t, new INumber[] { parameters[0], f.Numerator }));
                af.AddItem(runtime, this.ExecuteDiff(runtime, t, new INumber[] { parameters[0], f.Denominator }).Multiple(runtime, Number.New(-1)));
                return(af);
            }

            // 普通のlogの微分
            if (parameters[0] is NaturalLogarithm)
            {
                NaturalLogarithm e = parameters[0] as NaturalLogarithm;
                if (e.Pow.Equals(runtime, Number.New(1)))
                {
                    var prm = parameters[1].ExecuteDiff(runtime, t);
                    if (prm.Equals(runtime, Number.New(0)) ||
                        prm.Equals(runtime, Number.New(1)))
                    {
                        return(new Fraction(
                                   parameters[1], Number.New(1)));
                    }
                    else
                    {
                        MultipleFormula mf = new Expression.MultipleFormula();
                        mf.AddItem(runtime, prm);
                        mf.AddItem(runtime, new Fraction(
                                       parameters[1], Number.New(1)));
                        return(mf);
                    }
                }
            }
            else if (!FuncCalc.Runtime.Func.Differential.IsConstValue(runtime, parameters[0]))
            {
                throw new RuntimeException("底に定数以外が含まれたlogの微分を行うことはできません。");
            }

            INumber param1Diff = parameters[1].ExecuteDiff(runtime, t);

            if (param1Diff.Equals(runtime, Number.New(0)))
            {
                param1Diff = Number.New(1);
            }

            MultipleFormula den = new MultipleFormula();

            den.AddItem(runtime, parameters[1]);
            den.AddItem(runtime, new FuncedINumber(this, new INumber[] { new NaturalLogarithm(), parameters[0] }));
            Fraction res = new Fraction(den, param1Diff);

            return(res);
        }