public TokenStream OneOrMore(ComplexFunction function) { if (_error) { return(this); } int currentLevel = _queueNumber++; function(); if (_error) { DiscardData(currentLevel); return(this); } CommitData(currentLevel); int lastPosition = 0; int nextLevel = 0; while (!_error) { nextLevel = _queueNumber++; lastPosition = Position; function(); } DiscardData(nextLevel); CommitData(currentLevel); Position = lastPosition; _error = false; return(this); }
private static double GetMaxDeviation( double[] xValues, Complex[] yValues, ComplexFunction analyticSolution ) { Complex[] analyticValues = new Complex[yValues.Length]; for (int i = 0; i < yValues.Length; i++) { analyticValues[i] = analyticSolution(xValues[i]); } return(GetMaxDeviation(xValues, yValues, analyticValues)); }
private static void AssertMaxDeviationBelow( double accuracy, double[] xValues, Complex[] yValues, ComplexFunction analyticSolution ) { Complex[] analyticValues = new Complex[yValues.Length]; for (int i = 0; i < yValues.Length; i++) { analyticValues[i] = analyticSolution(xValues[i]); } AssertMaxDeviationBelow(accuracy, xValues, yValues, analyticValues); }
private static void MakePlotFile( double[] positions, Complex[] values, ComplexFunction analyticValues ) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < positions.Length; i++) { builder.AppendFormat("{0,-22}{1,-22}{2,-22}" + Environment.NewLine, positions[i].ToString(), values[i].Re.ToString(), analyticValues(positions[i]).Re.ToString()); } File.WriteAllText("RseSolverHydroTest.txt", builder.ToString()); }
public TokenStream ZeroOrOne(ComplexFunction function) { if (_error) { return(this); } int currentLevel = _queueNumber++; int lastPosition = Position; function(); if (_error) { DiscardData(currentLevel); _error = false; Position = lastPosition; return(this); } CommitData(currentLevel); return(this); }
static void Main(string[] args) { try { Console.Write("Value of argument: "); string userInput = Console.ReadLine() ?? throw new ApplicationException("Inpuc can't be null."); double argument = Double.Parse(userInput); ComplexFunction function = new ComplexFunction(); double result = function.Calculate(argument); Console.WriteLine($"Result: {result}"); } catch (Exception e) { Console.WriteLine(e); } Console.ReadKey(); }
public static Complex NewtoneRafson(ComplexFunction f, ComplexFunction df, Complex p0, double eps, out int iterationsTotal) { Complex p_prev; iterationsTotal = 0; //double epsManhattan = eps * 1.2; do { p_prev = p0; p0 = p0 - f(p0) / df(p0); if (++iterationsTotal > MAX_ITERATIONS) { return(Complex.NaN); } }while (Complex.Norm(p0 - p_prev) >= eps * Complex.Norm(p0)); //while (f(p0).x2y2 >= eps); //while ((p0 - p_prev).x2y2 >= eps); return(p0); }
public TokenStream Bounds(string left, ComplexFunction action, string right) { if (_error) { return(this); } Is(left); if (_error) { return(this); } int currentNumber = _queueNumber++; action(); Is(right); if (_error) { DiscardData(currentNumber); return(this); } CommitData(currentNumber); return(this); }
private void button1_Click(object sender, EventArgs e) { ReadPolynom(); if (poly1.N < 1) { MessageBox.Show("Задайте полином как минимум первой степени.", "Повторите ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } f = poly1.Evaluate; df = poly1.Diff().Evaluate; #region read eps, x1, x2, y1, y2 errorProvider.Clear(); try { eps = float.Parse(textE.Text); } catch (FormatException) { errorProvider.SetError(textE, "Wrong float number"); return; } if (eps < 0) { errorProvider.SetError(textE, "Has to be > 0"); return; } try { x1 = float.Parse(textX1.Text); } catch (FormatException) { errorProvider.SetError(textX1, "Wrong float number"); return; } try { x2 = float.Parse(textX2.Text); } catch (FormatException) { errorProvider.SetError(textX2, "Wrong float number"); return; } try { y1 = float.Parse(textY1.Text); } catch (FormatException) { errorProvider.SetError(textY1, "Wrong float number"); return; } try { y2 = float.Parse(textY2.Text); } catch (FormatException) { errorProvider.SetError(textY2, "Wrong float number"); return; } #endregion bgf = new BitmapGraphicForm(new PointF(x1, y1), new PointF(x2, y2)); bgf.ResizeEvent += new EventHandler(bgf_Resize); bgf.ZoomEvent += new EventHandler(bgf_ZoomEvent); float ratioM = (x2 - x1) / (y2 - y1); float ratioS = (float)bgf.PictureWidth / bgf.PictureHeight; Text += bgf.PictureWidth.ToString() + ", "; if (ratioM / ratioS > 1) { bgf.PictureHeight = (int)(bgf.PictureHeight * ratioS / ratioM); } else { bgf.PictureWidth = (int)(bgf.PictureWidth * ratioM / ratioS); } Text += bgf.PictureWidth.ToString() + ", "; PrecacheColors(); //eps *= eps; FindRoot(); }
public static ComplexFunction Generate(string name, object parameter = null) { ComplexFunction cf = null; switch (name.ToLower()) { //constants case "x": case "z": return(new ArgumentCF()); case "_": return(new ConstantCF(-1)); case "i": return(new ConstantCF(Complex.ImaginaryOne)); case "e": return(new ConstantCF(Math.E)); case "pi": return(new ConstantCF(Math.PI)); case "custom_constant": return(new ConstantCF((double)parameter)); //operators case "-": cf = new DifferenceCF(); break; case "+": cf = new SumCF(); break; case "/": cf = new QuotientCF(); break; case "*": case "&": cf = new ProductCF(); break; case "^": cf = new PowerCF(); break; case "tan(": cf = new TanCF(); break; case "tanh(": cf = new TanhCF(); break; case "sqrt(": cf = new SqrtCF(); break; case "sinh(": cf = new SinhCF(); break; case "sin(": cf = new SinCF(); break; case "log(": cf = new LogCF(); break; case "log10(": cf = new Log10CF(); break; case "[exp](": cf = new ExpCF(); break; case "cos(": cf = new CosCF(); break; case "cosh(": cf = new CoshCF(); break; case "atan(": cf = new AtanCF(); break; case "asin(": cf = new AsinCF(); break; case "acos(": cf = new AcosCF(); break; default: return(null); } if (parameter is ComplexFunction[]) { cf.InsertArguments((ComplexFunction[])parameter); } return(cf); }
public void Integrar(float Zx, float Zy, float r, int n, int p, float a, float b, string function) { limits = r; originalC = new Circulo(0, 0, r); float mayor = Mathf.Abs(Zx) > Mathf.Abs(Zy)? Mathf.Abs(Zx): Mathf.Abs(Zy); if (mayor >= r) { limits = mayor; } GenerarCirculo(originalC, originalCircle, cam1, originalxCoord, originalyCoord, textOriginalCoords); //Destroy(point); //point = Instantiate(pointPrefab, new Vector3(Zx, Zy, -0.15f), Quaternion.identity) as GameObject; point.transform.position = new Vector3(Zx, Zy, -0.15f); point.transform.localScale = new Vector3(1, 1, 1) * 0.3f * limits; Complejo Z0 = new Complejo(Zx, Zy); //Debug.Log( Z0.ToString() ); zPolar.text = Z0.ToPolarString(); if (Z0.radio == r && n != 0) { output.text = "indeterminado"; outputSimple.text = ""; } else if (Z0.radio > r || n == 0) { output.text = "0"; outputSimple.text = ""; } else { string outTxt; Complejo dospi; if (n == 1) { outTxt = "2πi*"; dospi = new Complejo(0, 2 * Mathf.PI); } else { outTxt = "2πi/" + (n - 1) + "!*("; dospi = new Complejo(0, (2 * Mathf.PI) / ComplexFunction.Factorial(n - 1)); } Complejo multiplicando = new Complejo(0, 0); switch (function) { case "Z^n": outTxt += "(" + Z0.ToBinomialString() + ")^" + p; multiplicando = ComplexFunction.dzPow(Z0, p, n - 1); break; case "e^z": outTxt += "e^(" + Z0.ToBinomialString() + ")"; multiplicando = ComplexFunction.Exp(Z0); break; case "sen(z)": outTxt += "sen(" + Z0.ToBinomialString() + ")"; multiplicando = ComplexFunction.dSin(Z0, n - 1); break; case "cos(z)": outTxt += "cos(" + Z0.ToBinomialString() + ")"; multiplicando = ComplexFunction.dCos(Z0, n - 1); break; case "cosh(z)": outTxt += "cosh(" + Z0.ToBinomialString() + ")"; multiplicando = ComplexFunction.dCosh(Z0, n - 1); break; case "senh(z)": outTxt += "senh(" + Z0.ToBinomialString() + ")"; multiplicando = ComplexFunction.dSinh(Z0, n - 1); break; case "a+ib": Complejo aib = new Complejo(a, b); outTxt += "(" + aib.ToBinomialString() + ")"; if (n <= 1) { multiplicando = aib; } break; } if (function != "Z^n") { outputSimple.fontSize = 20; outputSimple.text = "= " + (multiplicando * dospi).ToBinomialString(); } else { outputSimple.fontSize = 20; outputSimple.text = "= " + (multiplicando * dospi).ToBinomialString(); /*if (Z0.x==0 && Z0.y==0) { * outputSimple.fontSize=20; * outputSimple.text ="= 2πi * 0"; * }else{ * outputSimple.fontSize=15; * outputSimple.text="= 2πi * "+System.Math.Round( Z0.radio, 2)+"^n ( cos(n*"+System.Math.Round( 180*(Z0.angulo/Mathf.PI), 2)+ * ") + sen(n*"+System.Math.Round( 180*(Z0.angulo/Mathf.PI), 2)+"))"; * }*/ } if (n > 1) { outTxt += ")^(" + (n - 1) + ") deriv."; } output.text = outTxt; } }