Beispiel #1
0
        static bool RunTest(Expression Expr, Expression Result)
        {
            Expression T  = Binary.ApproxEqual(Expr, Result);
            Expression TE = T.Evaluate();

            bool passed = TE.IsTrue();

            if (!passed)
            {
                // Special case for NSolve since it does not produce exact results.
                Expression   pattern = "NSolve[x, y]";
                MatchContext m       = pattern.Matches(Expr);
                if (m != null)
                {
                    IEnumerable <Equal> f = Set.MembersOf(m["x"]).Cast <Equal>();
                    passed = f.All(i => Call.Abs(Binary.Subtract(i.Left, i.Right).Evaluate(Set.MembersOf(Result).Cast <Arrow>())) < 1e-3);
                }
            }

            if (!passed)
            {
                Console.WriteLine("{0}", Arrow.New(T, TE).ToPrettyString());
            }
            return(passed);
        }
        public override void Analyze(Analysis Mna)
        {
            Diode.Analyze(Mna, Gate, Source, IS, n);
            Diode.Analyze(Mna, Gate, Drain, IS, n);

            // The drain and source terminals are reversible in the JFET model, this
            // formulation is simpler than explicitly identifying normal/inverted mode.
            Expression Vgds   = Gate.V - Call.Min(Source.V, Drain.V);
            Expression Vds    = Drain.V - Source.V;
            Expression AbsVds = Call.Abs(Vds);

            //Vgds = Mna.AddUnknownEqualTo(Name + "gds", Vgds);

            Expression Vgds_t0 = Vgds - Vt0;

            Expression id = Call.Sign(Vds) * (Vgds >= Vt0) * Beta * (1 + Lambda * AbsVds) *
                            Call.If(AbsVds < Vgds_t0,
                                    // Linear region.
                                    AbsVds * (2 * Vgds_t0 - 1),
                                    // Saturation region.
                                    Vgds_t0 ^ 2);

            id = Mna.AddUnknownEqualTo("i" + Name + "d", id);
            CurrentSource.Analyze(Mna, Drain, Source, id);
        }
Beispiel #3
0
        static void Test(Expression Expr, Expression Result)
        {
            Expression T  = Binary.ApproxEqual(Expr, Result);
            Expression TE = T.Evaluate();

            bool passed = TE.IsTrue();

            if (!passed)
            {
                // Special case for NSolve since it does not produce exact results.
                Expression   pattern = "NSolve[x, y]";
                MatchContext m       = pattern.Matches(Expr);
                if (m != null)
                {
                    IEnumerable <Equal> f = Set.MembersOf(m["x"]).Cast <Equal>();
                    passed = f.All(i => Call.Abs(Binary.Subtract(i.Left, i.Right).Evaluate(Set.MembersOf(Result).Cast <Arrow>())) < 1e-3);
                }
            }
            if (!passed)
            {
                throw new Exception(String.Format("Test failed: {0} -> {1}", T, TE));
            }
        }