From de8f7a9baefec9cd3e1ecf7eaa02c479621464f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BA=D0=B5=D0=BB=D1=8C?= Date: Fri, 9 Mar 2018 11:06:41 +0700 Subject: [PATCH 1/9] =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyExpression.Core/CodeDomEvalEquation.cs | 36 ++++++++++++++++++++++ MyExpression.Core/MyExpression.Core.csproj | 1 + 2 files changed, 37 insertions(+) create mode 100644 MyExpression.Core/CodeDomEvalEquation.cs diff --git a/MyExpression.Core/CodeDomEvalEquation.cs b/MyExpression.Core/CodeDomEvalEquation.cs new file mode 100644 index 0000000..e16a4da --- /dev/null +++ b/MyExpression.Core/CodeDomEvalEquation.cs @@ -0,0 +1,36 @@ +// Copyright (c) 2018 Vladislav Prekel + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyExpression.Core +{ + public class CodeDomEvalEquation : IEquation + { + public CodeDomEval Function { get; private set; } + + public Interval Interval { get; private set; } + public double Step { get; private set; } + public double Epsilon { get; private set; } + + public CodeDomEvalEquation(CodeDomEval function, Interval interval, double step = 1e-3, double eps = 1e-8) + { + Function = function; + Interval = interval; + Step = step; + Epsilon = eps; + } + + public IList AllRoots => throw new NotImplementedException(); + + public IList Roots => throw new NotImplementedException(); + + public void Solve() + { + throw new NotImplementedException(); + } + } +} diff --git a/MyExpression.Core/MyExpression.Core.csproj b/MyExpression.Core/MyExpression.Core.csproj index ea85556..be868c9 100644 --- a/MyExpression.Core/MyExpression.Core.csproj +++ b/MyExpression.Core/MyExpression.Core.csproj @@ -42,6 +42,7 @@ + From 69999e78ed37b3458c3971c5ea9776b6fea01f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BA=D0=B5=D0=BB=D1=8C?= Date: Fri, 9 Mar 2018 11:48:26 +0700 Subject: [PATCH 2/9] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyExpression.Console/Program.cs | 26 ++++++---- MyExpression.Core/CodeDomEvalEquation.cs | 36 -------------- MyExpression.Core/FunctionEquation.cs | 55 ++++++++++++++++++++++ MyExpression.Core/MyExpression.Core.csproj | 2 +- 4 files changed, 72 insertions(+), 47 deletions(-) delete mode 100644 MyExpression.Core/CodeDomEvalEquation.cs create mode 100644 MyExpression.Core/FunctionEquation.cs diff --git a/MyExpression.Console/Program.cs b/MyExpression.Console/Program.cs index be8828e..41220a8 100644 --- a/MyExpression.Console/Program.cs +++ b/MyExpression.Console/Program.cs @@ -12,16 +12,16 @@ public class Program { private static void Main(string[] args) { - System.Console.Write("Equation: "); - var s = System.Console.ReadLine(); - System.Console.Write(" Epsilon: "); - var eps = System.Console.ReadLine(); - var p = Polynomial.Parse(s); - var e = new PolynomialEquation(p, Double.Parse(eps)); - e.Solve(); - //System.Console.WriteLine(String.Join(" ", e.AllRoots)); - System.Console.WriteLine(" Roots: " + String.Join(" ", e.Roots)); - System.Console.ReadKey(); + //System.Console.Write("Equation: "); + //var s = System.Console.ReadLine(); + //System.Console.Write(" Epsilon: "); + //var eps = System.Console.ReadLine(); + //var p = Polynomial.Parse(s); + //var e = new PolynomialEquation(p, Double.Parse(eps)); + //e.Solve(); + ////System.Console.WriteLine(String.Join(" ", e.AllRoots)); + //System.Console.WriteLine(" Roots: " + String.Join(" ", e.Roots)); + //System.Console.ReadKey(); //var s = System.Console.ReadLine(); //var evaluator = new CodeDomEval(s); @@ -51,6 +51,12 @@ private static void Main(string[] args) //e.Solve(); ////System.Console.WriteLine(String.Join(" ", e.AllRoots)); //System.Console.WriteLine(" Roots: " + String.Join(" ", e.Roots)); + + //var f = new CodeDomEval("pow(x, 3) - 2 * pow(x, 2) - x + 2"); + var f = new CodeDomEval("sin(x)"); + var e = new FunctionEquation(Math.Sin, new Interval(-5, 5)); + e.Solve(); + var r = e.AllRoots; } } } diff --git a/MyExpression.Core/CodeDomEvalEquation.cs b/MyExpression.Core/CodeDomEvalEquation.cs deleted file mode 100644 index e16a4da..0000000 --- a/MyExpression.Core/CodeDomEvalEquation.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2018 Vladislav Prekel - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MyExpression.Core -{ - public class CodeDomEvalEquation : IEquation - { - public CodeDomEval Function { get; private set; } - - public Interval Interval { get; private set; } - public double Step { get; private set; } - public double Epsilon { get; private set; } - - public CodeDomEvalEquation(CodeDomEval function, Interval interval, double step = 1e-3, double eps = 1e-8) - { - Function = function; - Interval = interval; - Step = step; - Epsilon = eps; - } - - public IList AllRoots => throw new NotImplementedException(); - - public IList Roots => throw new NotImplementedException(); - - public void Solve() - { - throw new NotImplementedException(); - } - } -} diff --git a/MyExpression.Core/FunctionEquation.cs b/MyExpression.Core/FunctionEquation.cs new file mode 100644 index 0000000..3ce69b7 --- /dev/null +++ b/MyExpression.Core/FunctionEquation.cs @@ -0,0 +1,55 @@ +// Copyright (c) 2018 Vladislav Prekel + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyExpression.Core +{ + public class FunctionEquation : IEquation + { + public Func Function { get; private set; } + + public Interval Interval { get; private set; } + public double Step { get; private set; } + public double Epsilon { get; private set; } + + public FunctionEquation(Func function, Interval interval, double step = 1e-3, double eps = 1e-8) + { + Function = function; + Interval = interval; + Step = step; + Epsilon = eps; + } + + public FunctionEquation(IFunctionX functionx, Interval interval, double step = 1e-3, double eps = 1e-8) + : this(functionx.Calculate, interval, step, eps) { } + + public IList AllRoots { get; private set; } + + public IList Roots { get; private set; } + + public void Solve() + { + AllRoots = new List(); + var x0 = Interval.Left; + var y0 = Function(x0); + var y = 0d; + for (var x = Interval.Left + Step; x <= Interval.Right; x += Step) + { + y = Function(x); + + if (y0 * y < 0) + { + var bs = new RecursiveBinarySearch(Function, new Interval(x0, x), Epsilon); + AllRoots.Add(bs.Solve()); + } + + y0 = y; + x0 = x; + } + } + } +} diff --git a/MyExpression.Core/MyExpression.Core.csproj b/MyExpression.Core/MyExpression.Core.csproj index be868c9..20d6c6c 100644 --- a/MyExpression.Core/MyExpression.Core.csproj +++ b/MyExpression.Core/MyExpression.Core.csproj @@ -42,7 +42,7 @@ - + From dea75d8f9bd1cf278ef6450020fbaefb6542c49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BA=D0=B5=D0=BB=D1=8C?= Date: Fri, 9 Mar 2018 11:57:38 +0700 Subject: [PATCH 3/9] =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyExpression.Console/Program.cs | 4 ++-- MyExpression.Wpf/MainWindow.xaml | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/MyExpression.Console/Program.cs b/MyExpression.Console/Program.cs index 41220a8..dd93d7a 100644 --- a/MyExpression.Console/Program.cs +++ b/MyExpression.Console/Program.cs @@ -53,8 +53,8 @@ private static void Main(string[] args) //System.Console.WriteLine(" Roots: " + String.Join(" ", e.Roots)); //var f = new CodeDomEval("pow(x, 3) - 2 * pow(x, 2) - x + 2"); - var f = new CodeDomEval("sin(x)"); - var e = new FunctionEquation(Math.Sin, new Interval(-5, 5)); + //var f = new CodeDomEval("sin(x)"); + var e = new FunctionEquation(Math.Sin, new Interval(-5, 5), eps: 1e-15); e.Solve(); var r = e.AllRoots; } diff --git a/MyExpression.Wpf/MainWindow.xaml b/MyExpression.Wpf/MainWindow.xaml index 8f5a504..20f7628 100644 --- a/MyExpression.Wpf/MainWindow.xaml +++ b/MyExpression.Wpf/MainWindow.xaml @@ -154,16 +154,21 @@ - + -