diff --git a/MyExpression.Console/Program.cs b/MyExpression.Console/Program.cs
index be8828e..dd93d7a 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), eps: 1e-15);
+ e.Solve();
+ var r = e.AllRoots;
}
}
}
diff --git a/MyExpression.Core.Tests/CodeDomEvalTests.cs b/MyExpression.Core.Tests/CodeDomEvalTests.cs
index 1e79596..b51c64f 100644
--- a/MyExpression.Core.Tests/CodeDomEvalTests.cs
+++ b/MyExpression.Core.Tests/CodeDomEvalTests.cs
@@ -1,10 +1,13 @@
-using NUnit.Framework;
+// Copyright (c) 2018 Vladislav Prekel
+
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using NUnit.Framework;
+
namespace MyExpression.Core.Tests
{
[TestFixture]
diff --git a/MyExpression.Core.Tests/FunctionEquationTests.cs b/MyExpression.Core.Tests/FunctionEquationTests.cs
new file mode 100644
index 0000000..eb372c2
--- /dev/null
+++ b/MyExpression.Core.Tests/FunctionEquationTests.cs
@@ -0,0 +1,23 @@
+// Copyright (c) 2018 Vladislav Prekel
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+
+namespace MyExpression.Core.Tests
+{
+ [TestFixture]
+ public class FunctionEquationTests
+ {
+ [Test]
+ public void CustomTest()
+ {
+ var e1 = new FunctionEquation((x) => Math.Sin(x) * Math.Sin(x) * Math.Cos(x) / Math.Tan(x), new Interval(-5, 5), 1e-3, 1e-5);
+ e1.Solve();
+ }
+ }
+}
diff --git a/MyExpression.Core.Tests/MyExpression.Core.Tests.csproj b/MyExpression.Core.Tests/MyExpression.Core.Tests.csproj
index ed4200c..689c430 100644
--- a/MyExpression.Core.Tests/MyExpression.Core.Tests.csproj
+++ b/MyExpression.Core.Tests/MyExpression.Core.Tests.csproj
@@ -48,6 +48,7 @@
+
diff --git a/MyExpression.Core/FunctionEquation.cs b/MyExpression.Core/FunctionEquation.cs
new file mode 100644
index 0000000..b1b2777
--- /dev/null
+++ b/MyExpression.Core/FunctionEquation.cs
@@ -0,0 +1,70 @@
+// 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 => AllRoots;
+
+ public void Solve()
+ {
+ AllRoots = new List();
+ var x0 = Interval.Left;
+ var y0 = Function(x0);
+ var y = 0d;
+ var fl = false;
+ var x1 = Double.NaN;
+ for (var x = Interval.Left + Step; x <= Interval.Right; x += Step)
+ {
+ y = Function(x);
+
+ if (!fl && Math.Abs(y) < Epsilon)
+ {
+ fl = true;
+ x1 = x;
+ }
+ if (fl && Math.Abs(y) >= Epsilon)
+ {
+ fl = false;
+ AllRoots.Add(x1);
+ }
+
+ var p = y0 * y;
+ if (!Double.IsInfinity(p) && !Double.IsNaN(p) && p < 0)
+ {
+ var bs = new RecursiveBinarySearch(Function, new Interval(x0, x), Epsilon);
+ x1 = bs.Solve();
+ if (!fl) AllRoots.Add(x1);
+ }
+
+ y0 = y;
+ x0 = x;
+ }
+ }
+ }
+}
diff --git a/MyExpression.Core/MyExpression.Core.csproj b/MyExpression.Core/MyExpression.Core.csproj
index ea85556..20d6c6c 100644
--- a/MyExpression.Core/MyExpression.Core.csproj
+++ b/MyExpression.Core/MyExpression.Core.csproj
@@ -42,6 +42,7 @@
+
diff --git a/MyExpression.Wpf/Icons/16x16.png b/MyExpression.Wpf/Icons/16x16.png
new file mode 100644
index 0000000..29930f0
Binary files /dev/null and b/MyExpression.Wpf/Icons/16x16.png differ
diff --git a/MyExpression.Wpf/Icons/240x240.png b/MyExpression.Wpf/Icons/240x240.png
new file mode 100644
index 0000000..1ce2d54
Binary files /dev/null and b/MyExpression.Wpf/Icons/240x240.png differ
diff --git a/MyExpression.Wpf/Icons/32x32.png b/MyExpression.Wpf/Icons/32x32.png
new file mode 100644
index 0000000..e93b65a
Binary files /dev/null and b/MyExpression.Wpf/Icons/32x32.png differ
diff --git a/MyExpression.Wpf/Icons/48x48.png b/MyExpression.Wpf/Icons/48x48.png
new file mode 100644
index 0000000..1339398
Binary files /dev/null and b/MyExpression.Wpf/Icons/48x48.png differ
diff --git a/MyExpression.Wpf/Icons/Icon1.ico b/MyExpression.Wpf/Icons/Icon1.ico
new file mode 100644
index 0000000..8dc393d
Binary files /dev/null and b/MyExpression.Wpf/Icons/Icon1.ico differ
diff --git a/MyExpression.Wpf/Icons/Thumbs.db b/MyExpression.Wpf/Icons/Thumbs.db
new file mode 100644
index 0000000..55d407f
Binary files /dev/null and b/MyExpression.Wpf/Icons/Thumbs.db differ
diff --git a/MyExpression.Wpf/MainWindow.xaml b/MyExpression.Wpf/MainWindow.xaml
index 8f5a504..ade8044 100644
--- a/MyExpression.Wpf/MainWindow.xaml
+++ b/MyExpression.Wpf/MainWindow.xaml
@@ -154,16 +154,21 @@
-
+
-
+
-
+
-
-
+
+
+
+
+
+
+
diff --git a/MyExpression.Wpf/MainWindow.xaml.cs b/MyExpression.Wpf/MainWindow.xaml.cs
index aeecc3d..a0741d8 100644
--- a/MyExpression.Wpf/MainWindow.xaml.cs
+++ b/MyExpression.Wpf/MainWindow.xaml.cs
@@ -203,6 +203,14 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
{
pe = new PolynomialEquation(p, Double.Parse(SolveEpsilon.Text));
}
+ else if (last.Function is CodeDomEval f)
+ {
+ var l = Double.Parse(SolveIntervalLeft.Text);
+ var r = Double.Parse(SolveIntervalRight.Text);
+ var step = Double.Parse(SolveStep.Text);
+ var eps = Double.Parse(SolveEpsilon.Text);
+ pe = new FunctionEquation(f, new Interval(l, r), step, eps);
+ }
else
{
pe = (IEquation)last.Function;
@@ -279,7 +287,12 @@ private void FunctionsListView_SelectionChanged(object sender, SelectionChangedE
if (g.Function is CodeDomEval)
{
TangentLim.IsEnabled = true;
- SolveButton.IsEnabled = false;
+ SolveButton.IsEnabled = true;
+ SolveStep.IsEnabled = true;
+ SolveIntervalLeft.IsEnabled = true;
+ SolveIntervalRight.IsEnabled = true;
+ MultipleRootsCheckBox.IsEnabled = false;
+ if (SolveEpsilon.Text == "1e-15") SolveEpsilon.Text = "1e-6";
}
else
{
@@ -293,6 +306,11 @@ private void FunctionsListView_SelectionChanged(object sender, SelectionChangedE
}
TangentLim.IsEnabled = false;
SolveButton.IsEnabled = true;
+ SolveStep.IsEnabled = false;
+ SolveIntervalLeft.IsEnabled = false;
+ SolveIntervalRight.IsEnabled = false;
+ MultipleRootsCheckBox.IsEnabled = true;
+ if (SolveEpsilon.Text == "1e-6") SolveEpsilon.Text = "1e-15";
}
}
}
diff --git a/MyExpression.Wpf/MyExpression.Wpf.csproj b/MyExpression.Wpf/MyExpression.Wpf.csproj
index 4b53e6a..ff3fd14 100644
--- a/MyExpression.Wpf/MyExpression.Wpf.csproj
+++ b/MyExpression.Wpf/MyExpression.Wpf.csproj
@@ -14,6 +14,7 @@
4
true
+ ..\MyExpression.Wpf\Icons\Icon1.ico
AnyCPU