public static double[,] EvalMatrixD_OneThread(AsyncArg arg, IExpression expr, DependencySpace depSpace, string[] deps, string var1, double len1, int steps1, string var2, double len2, int steps2) { expr = ExprUtils.GetCopy_Slow(expr); foreach (string dep in deps) { Complex?val = depSpace.Get(dep); if (val.HasValue) { expr = ExprSimplifier.Substitute(expr, dep, new ExprConst(val.Value.Real.ToString("f15"))); } } double[,] res = new double[steps1, steps2]; // t, x for (int n = 0; n < steps1; n++) { if (arg.Token.IsCancellationRequested) { return(null); } double v1 = len1 * n / steps1; IExpression substituted1 = ExprSimplifier.Substitute(expr, var1, new ExprConst(v1.ToString("f15"))); for (int j = 0; j < steps2; j++) { double v2 = len2 * j / steps2; IExpression substituted2 = ExprSimplifier.Substitute(substituted1, var2, new ExprConst(v2.ToString("f15"))); substituted2 = ExprSimplifier.Simplify(substituted2); res[n, j] = ExprDoubleSimplifier.CalcConstExpr(substituted2); } arg.Progress?.Report((n + 1) / (float)steps1); } return(res); }
private Complex GetComplexCoords(Point point, Complex?center = null) { var re = point.X; var im = point.Y; int lengthReal = (int)Fractal.Width; int lengthImaginary = (int)Fractal.Height; double radiusReal = Settings.Instance.Radius; double radiusImaginary = Settings.Instance.Radius * lengthImaginary / lengthReal; if (lengthReal < lengthImaginary) { radiusReal = Settings.Instance.Radius * lengthReal / lengthImaginary; radiusImaginary = Settings.Instance.Radius; } if (center == null) { double realPosition = Settings.Instance.Center.Real + (re * 2d - lengthReal) / lengthReal * radiusReal; double imaginaryPosition = Settings.Instance.Center.Imaginary - (im * 2d - lengthImaginary) / lengthImaginary * radiusImaginary; return(new Complex(realPosition, imaginaryPosition)); } else { double realPosition = center.Value.Real + (re * 2d - lengthReal) / lengthReal * radiusReal; double imaginaryPosition = center.Value.Imaginary - (im * 2d - lengthImaginary) / lengthImaginary * radiusImaginary; return(new Complex(realPosition, imaginaryPosition)); } }
public override Value DoOperation(Operator op, Value right, bool assign) { long?newValue = null; bool?boolValue = null; if (right == null) { newValue = Unary(op, Value); } else { var num = right as NumberValue; if (num == null) { return(null); } var other = num.AsDiscrete; if (num.IsDiscrete) { newValue = BinaryOperation(op, Value, other); if (newValue == null) { boolValue = Test(op, Value, other); } } else if (num.IsReal) { double?rValue = RealValue.BinaryOperation(op, Real, num.Real); if (rValue.HasValue) { return(RealValue.Get(rValue.Value)); } boolValue = RealValue.Test(op, Real, num.Real); } else { var complex = AsComplex; Complex?cValue = ComplexValue.BinaryOperation(op, complex, num.AsComplex); if (cValue.HasValue) { return(ComplexValue.Get(cValue.Value)); } boolValue = ComplexValue.Test(op, complex, num.AsComplex); } } if (boolValue.HasValue) { return(BoolValue.Get(boolValue.Value)); } if (!newValue.HasValue) { return(null); } if (assign) { return(SetValue(newValue.Value)); } return(Get(newValue.Value)); }
/// <summary> /// Converts complex number to color in RGB color space. /// Firstly converts the number to HSV color, and then to RGB. /// The HSV to RGB transformation is based on a standard algorithm. /// Special thanks to /// http://www.algorytm.org/modele-barw/transformacja-hsv-rgb.html /// for presenting the conversion algorithm. /// </summary> /// <param name="value">The complex number.</param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns>The brush (SolidColorBrush) of the color representing the number on the complex plane.</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Color color = Colors.LightGray; Complex?amplitude = value as Complex?; if (amplitude.HasValue) { double hue = amplitude.Value.Phase * 180 / Math.PI; if (hue < 0) { hue += 360; } double sat = 0.75; double val = 1.0; double red = 0, grn = 0, blu = 0; hue /= 60; int i = (int)Math.Floor(hue); double f = hue - i; double p = val * (1 - sat); double q = val * (1 - (sat * f)); double t = val * (1 - (sat * (1 - f))); if (i == 0) { red = val; grn = t; blu = p; } else if (i == 1) { red = q; grn = val; blu = p; } else if (i == 2) { red = p; grn = val; blu = t; } else if (i == 3) { red = p; grn = q; blu = val; } else if (i == 4) { red = t; grn = p; blu = val; } else if (i == 5) { red = val; grn = p; blu = q; } byte R = (byte)(red * 255); byte G = (byte)(grn * 255); byte B = (byte)(blu * 255); color = Color.FromArgb(255, R, G, B); } return(new SolidColorBrush(color)); }
public OutputState(ulong initialValue, Complex amplitude, int width) { _width = width; _bits = new char[width]; _value = initialValue; UpdateBits(initialValue); _amplitute = amplitude; _probability = Math.Pow(amplitude.Magnitude, 2); }
public OutputState(ulong initialValue, double probability, int width) { _width = width; _bits = new char[width]; _value = initialValue; UpdateBits(initialValue); _amplitute = null; _probability = probability; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Complex?arg = value as Complex?; if (arg.HasValue) { return(String.Format(_formatter, "{0:I2}", arg.Value)); } return(""); }
public override bool Equals(object obj) { Complex?other = obj as Complex?; if (other == null) { return(false); } return(this.Equals((Complex)other)); }
int IComparable.CompareTo(object obj) { Complex?other = obj as Complex?; if (other == null) { return(0); } return(CompareTo((Complex)other)); }
public bool Equals(Complex?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Real.Equals(other.Real) && Imagine.Equals(other.Imagine)); }
public override Value DoOperation(Operator op, Value right, bool assign) { double?newValue = null; bool? boolResult = null; if (right == null) { newValue = Unary(op, Value); } else { var num = right as NumberValue; if (num == null) { return(null); } if (!num.IsReal) { Complex?cValue = ComplexValue.BinaryOperation(op, AsComplex, num.AsComplex); if (cValue.HasValue) { return(ComplexValue.Get(cValue.Value)); } boolResult = ComplexValue.Test(op, AsComplex, num.AsComplex); } else { newValue = BinaryOperation(op, Value, num.Real); if (newValue == null) { boolResult = Test(op, Value, num.Real); } } } if (boolResult.HasValue) { return(BoolValue.Get(boolResult.Value)); } if (!newValue.HasValue) { return(null); } if (assign) { return(SetValue(newValue.Value)); } return(Get(newValue.Value)); }
public static double[,] EvalMatrixD(AsyncArg arg, IExpression expr, DependencySpace depSpace, string[] deps, string var1, double len1, int steps1, string var2, double len2, int steps2) { expr = ExprUtils.GetCopy_Slow(expr); foreach (string dep in deps) { Complex?val = depSpace.Get(dep); if (val.HasValue) { expr = ExprSimplifier.Substitute(expr, dep, new ExprConst(val.Value.Real.ToString("f15"))); } } double[,] res = new double[steps1, steps2]; // t, x if (!ExprSimplifier.IsDependsOn(expr, var1)) { double[] xArr = EvalArrayD(expr, depSpace, deps, var2, len2, steps2); for (int j = 0; j < steps2; j++) { for (int i = 0; i < steps1; i++) { res[i, j] = xArr[j]; } } return(res); } if (!ExprSimplifier.IsDependsOn(expr, var2)) { double[] xArr = EvalArrayD(expr, depSpace, deps, var1, len1, steps1); for (int i = 0; i < steps1; i++) { for (int j = 0; j < steps2; j++) { res[i, j] = xArr[i]; } } return(res); } int[] progress = new int[Environment.ProcessorCount]; int interval = (int)Math.Ceiling(steps1 / (double)progress.Length); Parallel.For(0, progress.Length, (index) => EvalMatrixD(arg, expr, res, steps1, progress, index, var1, len1 / steps1, index * interval, Math.Min((index + 1) * interval, steps1), var2, len2 / steps2, steps2)); return(res); }
public static double[] EvalArrayD(IExpression expr, DependencySpace depSpace, string[] deps, string varName, double length, int sections) { expr = ExprUtils.GetCopy_Slow(expr); foreach (string dep in deps) { Complex?val = depSpace.Get(dep); if (val.HasValue) { expr = ExprSimplifier.Substitute(expr, dep, new ExprConst(val.Value.Real.ToString("f15"))); } } double[] u0 = new double[sections]; for (int j = 0; j < u0.Length; j++) { double v = length * j / u0.Length; IExpression substituted = ExprSimplifier.Substitute(expr, varName, new ExprConst(v.ToString("f15"))); substituted = ExprSimplifier.Simplify(substituted); u0[j] = ExprDoubleSimplifier.CalcConstExpr(substituted); } return(u0); }
public override Value DoOperation(Operator op, Value right, bool assign) { var number = right as NumberValue; Complex?newValue = null; bool? boolValue = null; if (number == null) { switch (op) { case Operator.Negate: newValue = -Value; break; case Operator.Substitute: case Operator.Evaluate: return(this); case Operator.Magnitude: return(RealValue.Get(Magnitude)); } } else { newValue = BinaryOperation(op, Value, number.AsComplex); if (newValue == null) { boolValue = Test(op, Value, number.AsComplex); } } if (boolValue.HasValue) { return(BoolValue.Get(boolValue.Value)); } else if (newValue.HasValue) { return(assign ? SetValue(newValue.Value) : Get(newValue.Value)); } return(null); }
public int CompareTo(Complex?other) { if (other is null) { throw new ArgumentNullException(); } if (Real > other.Real) { return(1); } if (Real < other.Real) { return(-1); } if (Imagine < other.Imagine) { return(-1); } if (Imagine > other.Imagine) { return(1); } return(0); }
protected override void OnMouseDown(MouseEventArgs e) { Size size = this.ClientSize; this._DragPoint = this.Camera.Transform(e.X, e.Y, size.Width, size.Height); }
public void Read(BinaryReader rd) { _value = rd.ReadNullable(vr => new Complex(rd.ReadDouble(), rd.ReadDouble())); }
public SqlComplex(Complex number) { _value = number; }
public static Complex Iterate(Func <Complex, Complex> fx, Func <Complex, Complex> dydx, Complex?guess = null, int?iterations = DefaultIterations, int?rounding = DefaultRounding) { Complex x1 = guess ?? DefaultGuess, x0; for (int i = 1; i <= (iterations ?? i); ++i) { x0 = x1; x1 = x0 - (fx(x0) / dydx(x0)); if (rounding.HasValue) { x1 = new Complex(Math.Round(x1.Real, rounding.Value), Math.Round(x1.Imaginary, rounding.Value)); } if (x0 == x1) { return(x0); } } throw new IterationsExceededException <Complex>(x1); }
public void SetValue(Complex value) { IndeterminateValue = value; }
public static Complex dnaNullableComplex(Complex?c) { //return val.HasValue ? val.Value : TestEnum.Zero; return(c ?? new Complex(111, 222)); }
protected override void OnMouseUp(MouseEventArgs e) { this._DragPoint = null; }
public async Task Reset(Complex?from = null, Complex?to = null) { await RunAsync(from ?? new Complex(-1.5, -1), to ?? new Complex(1, 1)); }
private static Complex Iterate(Func <Complex, Complex> fx, Func <Complex, Complex> dydx, Complex?guess = null) { try { return(guess.HasValue ? NewtonRaphson.Iterate(fx, dydx, guess) : NewtonRaphson.Iterate(fx, dydx)); } catch (IterationsExceededException <Complex> exc) { return(exc.LastValue); } }
public Indeterminate(char symbol, int exponent) { Symbol = symbol; Exponent = exponent; IndeterminateValue = null; }