Exemplo n.º 1
0
 public static void Plot(Expression f, Variable x, Constant x0, Constant x1)
 {
     ComputerAlgebra.Plotting.Plot p = new ComputerAlgebra.Plotting.Plot()
     {
         x0 = (double)x0,
         x1 = (double)x1,
         Title = f.ToString(),
         xLabel = x.ToString(),
     };
     foreach (Expression i in Set.MembersOf(f))
         p.Series.Add(new ComputerAlgebra.Plotting.Function(ExprFunction.New(i, x)) { Name = i.ToString() });
 }
Exemplo n.º 2
0
 protected override string VisitVariable(Variable V)
 {
     return(V.Name);
 }
Exemplo n.º 3
0
        public double RunTest(Circuit.Circuit C, Simulation S, Func<double, double> Vin, int Samples, string Name)
        {
            double t0 = (double)S.Time;
            double T = S.TimeStep;

            int N = 353;
            double[] input = new double[N];

            List<List<double>> output = S.Output.Select(i => new List<double>(Samples)).ToList();
            List<double[]> buffers = S.Output.Select(i => new double[N]).ToList();

            double time = 0.0;
            int samples = 0;
            double t = 0;
            for (; samples < Samples; samples += N)
            {
                for (int n = 0; n < N; ++n, t += T)
                    input[n] = Vin(t);

                long a = Timer.Counter;
                S.Run(input, buffers);
                time += Timer.Delta(a);

                for (int i = 0; i < S.Output.Count(); ++i)
                    output[i].AddRange(buffers[i]);
            }
            simulateTime += time;

            int t1 = Math.Min(samples, 4000);

            Log.WriteLine("Performance {0}", Quantity.ToString(samples / time, Units.Hz));

            Plot p = new Plot()
            {
                Title = Name,
                Width = 800,
                Height = 400,
                x0 = t0,
                x1 = T * t1,
                xLabel = "Time (s)",
                yLabel = "Voltage (V)",
            };

            p.Series.AddRange(output.Select((i, j) => new Scatter(
                i.Take(t1)
                .Select((k, n) => new KeyValuePair<double, double>(n * T, k)).ToArray()) { Name = S.Output.ElementAt(j).ToString() }));
            return samples / time;
        }
Exemplo n.º 4
0
 private static Expression ChildPattern(ref int unique)
 {
     unique++;
     return(Variable.New("_" + unique.ToString()));
 }