Skip to content

Commit e396255

Browse files
committed
Revert "-"
This reverts commit 9d6de3b.
1 parent 9d6de3b commit e396255

File tree

2 files changed

+200
-124
lines changed

2 files changed

+200
-124
lines changed

README.md

Lines changed: 200 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Math Classes in CSharp
2+
23
[![NuGet version](https://buildstats.info/nuget/MathClassesDmPa)](https://www.nuget.org/packages/MathClassesDmPa/)
4+
35
## About
6+
47
Set of simple mathematical classes in C# including
8+
59
* Vectors (with complex cases)
610
* Matrixes (not only square)
711
* Polynoms (including intergation and derivatives)
@@ -15,17 +19,29 @@ Set of simple mathematical classes in C# including
1519
* Net functions methods
1620
* Function optimization (including swarm algorithm for 1/2/n dimentions)
1721
* Function values memorising (memoize) for parallel/non-parallel cases
22+
1823
I've been creating this library since 2017 for my university homework and firts job. Writing it I was practicing my C# skills from C# 3.0 to C# 7.1, getting coding experience.
24+
1925
There are .NET Framework version and newest supported .NET Core (named MathClassesLibrary) copy with few upgrading.
26+
2027
See some examples of using and results [here](https://github.com/PasaOpasen/Old_Math_CSharpCpp_Projects) or [here](https://github.com/PasaOpasen/Search-for-defects-in-plates)
28+
2129
## How to download
30+
2231
Downloading in VS:
32+
2333
![1](https://github.com/PasaOpasen/MathClasses/blob/master/gifs/download.gif)
34+
2435
## Usage:
36+
2537
![1](https://github.com/PasaOpasen/MathClasses/blob/master/gifs/usage.gif)
38+
2639
## Examples
40+
2741
Below you can see examples of using most used classes of this library.
42+
2843
Firstly load the objects and set aliases:
44+
2945
```csharp
3046
using MathNet.Numerics;
3147
using System;
@@ -34,133 +50,208 @@ using МатКлассы;
3450
using Complex = МатКлассы.Number.Complex;
3551
using Rational = МатКлассы.Number.Rational;
3652
```
53+
3754
### Complex numbers
55+
3856
```csharp
39-
var a = new Complex(1);
40-
a.Show(); // 1
41-
var b = new Complex(2.5, 1.5);
42-
b.Show(); // 2,5 + 1,5i
43-
b.Conjugate.Show(); // 2,5 - 1,5i
44-
b.Re.Show(); // 2,5
45-
b.Im.Show(); // 1,5
46-
b.Abs.Show(); // 2,9154759474226504
47-
b.Arg.Show(); // 0,5404195002705842
48-
var c = a / b + 3 + 5.6 + a * b +
49-
Complex.Cos(b) + Complex.Sin(a + b) + Complex.Ch(a * b * b) +
50-
Complex.Ln(b) + Complex.Exp(a) + Complex.Expi(10);
51-
c.Show(); // 21,099555214728547 + 23,649577072514752i
52-
c.Round(4).Show(); // 21,0996 + 23,6496i
53-
c.Swap.Show(); // 23,649577072514752 + 21,099555214728547i
54-
c.Pow(3.5).Show(); // -175884,94745749474 + 34459,051603806576i
55-
new CVectors(Complex.Radical(a + b + b * b, 7)).Show(); // (1,4101632808375018 + 0,1774107754735756i 0,7405170949635271 + 1,2131238576267886i -0,4867535672138724 + 1,3353299317700824i -1,3474888653159458 + 0,4520053315239409i -1,1935375640715047 - 0,771688502588176i -0,14082813335184957 - 1,4142851546746704i 1,0179277541521443 - 0,9918962391315406i)
56-
Complex.ToComplex("1+2i").Show(); // 1 + 2i
57-
Complex.ToComplex("-1 + 2,346e-5i").Show(); // -1 + 2,346e-5i
57+
var a = new Complex(1);
58+
a.Show(); // 1
59+
60+
var b = new Complex(2.5, 1.5);
61+
b.Show(); // 2,5 + 1,5i
62+
b.Conjugate.Show(); // 2,5 - 1,5i
63+
b.Re.Show(); // 2,5
64+
b.Im.Show(); // 1,5
65+
b.Abs.Show(); // 2,9154759474226504
66+
b.Arg.Show(); // 0,5404195002705842
67+
68+
69+
var c = a / b + 3 + 5.6 + a * b +
70+
Complex.Cos(b) + Complex.Sin(a + b) + Complex.Ch(a * b * b) +
71+
Complex.Ln(b) + Complex.Exp(a) + Complex.Expi(10);
72+
c.Show(); // 21,099555214728547 + 23,649577072514752i
73+
c.Round(4).Show(); // 21,0996 + 23,6496i
74+
75+
c.Swap.Show(); // 23,649577072514752 + 21,099555214728547i
76+
c.Pow(3.5).Show(); // -175884,94745749474 + 34459,051603806576i
77+
78+
new CVectors(Complex.Radical(a + b + b * b, 7)).Show(); // (1,4101632808375018 + 0,1774107754735756i 0,7405170949635271 + 1,2131238576267886i -0,4867535672138724 + 1,3353299317700824i -1,3474888653159458 + 0,4520053315239409i -1,1935375640715047 - 0,771688502588176i -0,14082813335184957 - 1,4142851546746704i 1,0179277541521443 - 0,9918962391315406i)
79+
80+
Complex.ToComplex("1+2i").Show(); // 1 + 2i
81+
Complex.ToComplex("-1 + 2,346e-5i").Show(); // -1 + 2,346e-5i
5882
```
83+
5984
### Rational numbers
85+
6086
```csharp
6187
var a = new Rational(2123343454656);
62-
a.Show(); // 2123343454656
63-
var b = new Rational(455, 15);
64-
b.Show(); // 91/3
65-
b.ShowMixed(); // 30 + 1/3
66-
(a + b).IntPart.Show(); // 2123343454686
67-
b.FracPart.Show(); // 1/3
68-
var c = new Rational(22.16);
69-
c.Show(); // 554/25
70-
Rational.ToRational(-12.46572).Show(); // -311643/25000
71-
(b + c).ShowMixed(); // 52 + 37/75
72-
(a / 3213443 + b * c).ShowMixed(); // 661441 + 40262377/241008225
88+
a.Show(); // 2123343454656
89+
90+
var b = new Rational(455, 15);
91+
b.Show(); // 91/3
92+
b.ShowMixed(); // 30 + 1/3
93+
94+
(a + b).IntPart.Show(); // 2123343454686
95+
b.FracPart.Show(); // 1/3
96+
97+
var c = new Rational(22.16);
98+
c.Show(); // 554/25
99+
100+
Rational.ToRational(-12.46572).Show(); // -311643/25000
101+
102+
(b + c).ShowMixed(); // 52 + 37/75
103+
104+
(a / 3213443 + b * c).ShowMixed(); // 661441 + 40262377/241008225
73105
```
106+
74107
### 2D Points
108+
75109
```csharp
76110
var p1 = new Point(1, 4);
77111
p1.Show(); // (1 , 4)
78-
Point.Add(p1, 3).Show(); // (4 , 7)
79-
Point.Add(p1, -1, -3).Show(); // (0 , 1)
80-
Point.Eudistance(new Point(0.4, -2), new Point(1, 1)).Show(); // 3,059411708155671
81-
var gen = Expendator.ThreadSafeRandomGen(100);
82-
var points = Enumerable.Range(0, 10).Select(s => new Point(gen.NextDouble(), gen.NextDouble())).ToArray();
83-
Point.Center(points).Show(); // (0,6655678990602344 , 0,531635367093438)
84-
points = Point.Points(x => Math.Sin(x) + 2 * Math.Round(x), n: 10, a: -0.2, b: 0.2);
85-
foreach (var p in points)
86-
Console.WriteLine(p);
87-
//(0, 6655678990602344, 0, 531635367093438)
88-
//(-0, 2, -0, 19866933079506122)
89-
//(-0, 16, -0, 15931820661424598)
90-
//(-0, 12000000000000001, -0, 11971220728891938)
91-
//(-0, 08000000000000002, -0, 07991469396917271)
92-
//(-0, 04000000000000001, -0, 03998933418663417)
93-
//(0, 0)
94-
//(0, 03999999999999998, 0, 03998933418663414)
95-
//(0, 08000000000000002, 0, 07991469396917271)
96-
//(0, 12, 0, 11971220728891936)
97-
//(0, 15999999999999998, 0, 15931820661424595)
98-
//(0, 2, 0, 19866933079506122)
112+
113+
Point.Add(p1, 3).Show(); // (4 , 7)
114+
Point.Add(p1, -1, -3).Show(); // (0 , 1)
115+
116+
Point.Eudistance(new Point(0.4, -2), new Point(1, 1)).Show(); // 3,059411708155671
117+
118+
var gen = Expendator.ThreadSafeRandomGen(100);
119+
120+
var points = Enumerable.Range(0, 10).Select(s => new Point(gen.NextDouble(), gen.NextDouble())).ToArray();
121+
122+
Point.Center(points).Show(); // (0,6655678990602344 , 0,531635367093438)
123+
124+
points = Point.Points(x => Math.Sin(x) + 2 * Math.Round(x), n: 10, a: -0.2, b: 0.2);
125+
126+
foreach (var p in points)
127+
Console.WriteLine(p);
128+
129+
//(0, 6655678990602344, 0, 531635367093438)
130+
//(-0, 2, -0, 19866933079506122)
131+
//(-0, 16, -0, 15931820661424598)
132+
//(-0, 12000000000000001, -0, 11971220728891938)
133+
//(-0, 08000000000000002, -0, 07991469396917271)
134+
//(-0, 04000000000000001, -0, 03998933418663417)
135+
//(0, 0)
136+
//(0, 03999999999999998, 0, 03998933418663414)
137+
//(0, 08000000000000002, 0, 07991469396917271)
138+
//(0, 12, 0, 11971220728891936)
139+
//(0, 15999999999999998, 0, 15931820661424595)
140+
//(0, 2, 0, 19866933079506122)
99141
```
142+
100143
### Function parser
144+
101145
```csharp
102-
var gen = Expendator.ThreadSafeRandomGen(1);
103-
Func<double, double> f1 = Parser.GetDelegate("cos(x)+sin(x/2+4,6)*exp(-sqr(x))+abs(x)^0,05");
104-
Func<double, double> f2 = x => Math.Cos(x) + Math.Sin(x / 2 + 4.6) * Math.Exp(-x * x) + Math.Pow(Math.Abs(x), 0.05);
105-
for (int i = 0; i < 5; i++)
106-
{
107-
var d = gen.NextDouble() * 50;
108-
$"{f1(d)} == {f2(d)}".Show();
109-
}
110-
//2,1254805141764708 == 2,1254805141764708
111-
//1,8237614071831993 == 1,8237614071831991
112-
//0,9607774340933849 == 0,9607774340933849
113-
//1,8366859282256982 == 1,8366859282256982
114-
//1,3013656833866554 == 1,3013656833866554
115-
Func<Complex, Complex> c1 = ParserComplex.GetDelegate("Re(z)*Im(z) + sh(z)*I + sin(z)/100");
116-
Func<Complex, Complex> c2 = z => z.Re * z.Im + Complex.Sh(z) * Complex.I + Complex.Sin(z) / 100;
117-
for (int i = 0; i < 5; i++)
118-
{
119-
var d = new Complex(gen.NextDouble() * 50, gen.NextDouble() * 10);
120-
$"{c1(d)} == {c2(d)}".Show();
121-
}
122-
// 485696399,00749403 - 1151202339,537752i == 485696398,8506223 - 1151202339,7349265i
123-
//- 1,328008130324937E+20 + 8,291419281824573E+19i == -1,328008130324937E+20 + 8,291419281824573E+19i
124-
// - 12609203585138,465 + 42821192159972,99i == -12609203585138,78 + 42821192159972,99i
125-
//7270,488386388151 - 121362,61308893963i == 7270,344179063162 - 121362,52416901031i
126-
//- 7,964336745137357E+20 + 1,3345594600169975E+21i == -7,964336745137357E+20 + 1,3345594600169975E+21i
146+
147+
var gen = Expendator.ThreadSafeRandomGen(1);
148+
149+
Func<double, double> f1 = Parser.GetDelegate("cos(x)+sin(x/2+4,6)*exp(-sqr(x))+abs(x)^0,05");
150+
Func<double, double> f2 = x => Math.Cos(x) + Math.Sin(x / 2 + 4.6) * Math.Exp(-x * x) + Math.Pow(Math.Abs(x), 0.05);
151+
152+
for (int i = 0; i < 5; i++)
153+
{
154+
var d = gen.NextDouble() * 50;
155+
$"{f1(d)} == {f2(d)}".Show();
156+
}
157+
//2,1254805141764708 == 2,1254805141764708
158+
//1,8237614071831993 == 1,8237614071831991
159+
//0,9607774340933849 == 0,9607774340933849
160+
//1,8366859282256982 == 1,8366859282256982
161+
//1,3013656833866554 == 1,3013656833866554
162+
163+
Func<Complex, Complex> c1 = ParserComplex.GetDelegate("Re(z)*Im(z) + sh(z)*I + sin(z)/100");
164+
Func<Complex, Complex> c2 = z => z.Re * z.Im + Complex.Sh(z) * Complex.I + Complex.Sin(z) / 100;
165+
166+
for (int i = 0; i < 5; i++)
167+
{
168+
var d = new Complex(gen.NextDouble() * 50, gen.NextDouble() * 10);
169+
170+
$"{c1(d)} == {c2(d)}".Show();
171+
}
172+
173+
// 485696399,00749403 - 1151202339,537752i == 485696398,8506223 - 1151202339,7349265i
174+
//- 1,328008130324937E+20 + 8,291419281824573E+19i == -1,328008130324937E+20 + 8,291419281824573E+19i
175+
// - 12609203585138,465 + 42821192159972,99i == -12609203585138,78 + 42821192159972,99i
176+
//7270,488386388151 - 121362,61308893963i == 7270,344179063162 - 121362,52416901031i
177+
//- 7,964336745137357E+20 + 1,3345594600169975E+21i == -7,964336745137357E+20 + 1,3345594600169975E+21i
178+
127179
```
128180
### Real vectors
181+
129182
```csharp
130-
var v = new Vectors(5);
131-
v.Show(); // ( 0 0 0 0 0 )
132-
v = new Vectors(5, 1.0);
133-
v.Show(); // ( 1 1 1 1 1 )
134-
v = new Vectors(1, 2, 3, 4, 5, 6, 7, 9.5, -2, 3);
135-
v.Show(); // ( 1 2 3 4 5 6 7 9,5 -2 3 )
136-
v = new Vectors(new double[] { 1, 2, 3,-3,-2,-1,0 });
137-
v.Show(); // ( 1 2 3 -3 -2 -1 0 )
138-
v[6].Show(); // 0
139-
v.EuqlidNorm.Show(); // 0,7559289460184545
140-
v.Normalize(0, 1).Show(); // ( 0,6666666666666666 0,8333333333333333 1 0 0,16666666666666666 0,3333333333333333 0,5 )
141-
v.Range.Show(); // 6
142-
v.SubVector(4).Show(); // ( 1 2 3 -3 )
143-
v.Average.Show(); // 1,7142857142857142
144-
v.Contain(3).Show(); // True
145-
v.Normalize(-0.5, 0.5).ToRationalStringTab().Show(); // ( 1/6 1/3 1/2 -1/2 -1/3 -1/6 0 )
146-
var p = Vectors.Create(dim: 7, min: 0, max: 2);
147-
p.Show(); // ( 1,4585359040647745 1,7510524201206863 1,4706563879735768 0,45403700647875667 0,022686069831252098 1,9943826524540782 0,3851787596940994 )
148-
Vectors.Mix(v, p).Show();
149-
// ( 1 1,4585359040647745 2 1,7510524201206863 3 1,4706563879735768 -3 0,45403700647875667 -2 0,022686069831252098 -1 1,9943826524540782 0 0,3851787596940994 )
150-
(v + p).Show(); // ( 2,4585359040647745 3,7510524201206863 4,470656387973577 -2,5459629935212433 -1,977313930168748 0,9943826524540782 0,3851787596940994 )
151-
(v * p).Show(); // 5,970744096674025
152-
Vectors.CompMult(v, p).Show(); // ( 1,4585359040647745 3,5021048402413726 4,41196916392073 -1,36211101943627 -0,045372139662504196 -1,9943826524540782 0 )
153-
(2.4*v.AbsVector - p/2).Sort.BinaryApproxSearch(1.5).Show(); // 1,4028086737729608
183+
var v = new Vectors(5);
184+
v.Show(); // ( 0 0 0 0 0 )
185+
186+
v = new Vectors(5, 1.0);
187+
v.Show(); // ( 1 1 1 1 1 )
188+
189+
v = new Vectors(1, 2, 3, 4, 5, 6, 7, 9.5, -2, 3);
190+
v.Show(); // ( 1 2 3 4 5 6 7 9,5 -2 3 )
191+
192+
v = new Vectors(new double[] { 1, 2, 3,-3,-2,-1,0 });
193+
v.Show(); // ( 1 2 3 -3 -2 -1 0 )
194+
195+
196+
v[6].Show(); // 0
197+
198+
v.EuqlidNorm.Show(); // 0,7559289460184545
199+
200+
v.Normalize(0, 1).Show(); // ( 0,6666666666666666 0,8333333333333333 1 0 0,16666666666666666 0,3333333333333333 0,5 )
201+
202+
v.Range.Show(); // 6
203+
204+
v.SubVector(4).Show(); // ( 1 2 3 -3 )
205+
206+
v.Average.Show(); // 1,7142857142857142
207+
208+
v.Contain(3).Show(); // True
209+
210+
v.Normalize(-0.5, 0.5).ToRationalStringTab().Show(); // ( 1/6 1/3 1/2 -1/2 -1/3 -1/6 0 )
211+
212+
var p = Vectors.Create(dim: 7, min: 0, max: 2);
213+
p.Show(); // ( 1,4585359040647745 1,7510524201206863 1,4706563879735768 0,45403700647875667 0,022686069831252098 1,9943826524540782 0,3851787596940994 )
214+
215+
Vectors.Mix(v, p).Show();
216+
// ( 1 1,4585359040647745 2 1,7510524201206863 3 1,4706563879735768 -3 0,45403700647875667 -2 0,022686069831252098 -1 1,9943826524540782 0 0,3851787596940994 )
217+
218+
(v + p).Show(); // ( 2,4585359040647745 3,7510524201206863 4,470656387973577 -2,5459629935212433 -1,977313930168748 0,9943826524540782 0,3851787596940994 )
219+
(v * p).Show(); // 5,970744096674025
220+
Vectors.CompMult(v, p).Show(); // ( 1,4585359040647745 3,5021048402413726 4,41196916392073 -1,36211101943627 -0,045372139662504196 -1,9943826524540782 0 )
221+
222+
(2.4*v.AbsVector - p/2).Sort.BinaryApproxSearch(1.5).Show(); // 1,4028086737729608
223+
154224
```
225+
155226
### Complex vectors
227+
156228
```csharp
157-
var v1 = new Vectors(1, 2, 3, 4, 5);
158-
var v2 = new Vectors(0, 3, 4, 3, -5);
159-
var c = new CVectors(R: v1, I: v2);
160-
c.Show(); // (1 2 + 3i 3 + 4i 4 + 3i 5 - 5i)
161-
c.Re.Show(); // ( 1 2 3 4 5 )
162-
c.Normalize.Show(); // (0,1414213562373095 0,282842712474619 + 0,42426406871192845i 0,42426406871192845 + 0,565685424949238i 0,565685424949238 + 0,42426406871192845i 0,7071067811865475 - 0,7071067811865475i)
163-
c.Conjugate.Show(); // (1 2 - 3i 3 - 4i 4 - 3i 5 + 5i)
164-
var b = new CVectors(new Complex[] { new Complex(1, 2), new Complex(4, 5), new Complex(4.4, 0), new Complex(), new Complex(4.5) });
165-
(c/5 + b*(0.2-Complex.I)).Show(); // (2,4000000000000004 - 0,6i 6,2 - 2,4i 1,48 - 3,6000000000000005i 0,8 + 0,6i 1,9 - 5,5i)
229+
var v1 = new Vectors(1, 2, 3, 4, 5);
230+
var v2 = new Vectors(0, 3, 4, 3, -5);
231+
232+
var c = new CVectors(R: v1, I: v2);
233+
234+
c.Show(); // (1 2 + 3i 3 + 4i 4 + 3i 5 - 5i)
235+
c.Re.Show(); // ( 1 2 3 4 5 )
236+
c.Normalize.Show(); // (0,1414213562373095 0,282842712474619 + 0,42426406871192845i 0,42426406871192845 + 0,565685424949238i 0,565685424949238 + 0,42426406871192845i 0,7071067811865475 - 0,7071067811865475i)
237+
c.Conjugate.Show(); // (1 2 - 3i 3 - 4i 4 - 3i 5 + 5i)
238+
239+
var b = new CVectors(new Complex[] { new Complex(1, 2), new Complex(4, 5), new Complex(4.4, 0), new Complex(), new Complex(4.5) });
240+
241+
(c/5 + b*(0.2-Complex.I)).Show(); // (2,4000000000000004 - 0,6i 6,2 - 2,4i 1,48 - 3,6000000000000005i 0,8 + 0,6i 1,9 - 5,5i)
242+
166243
```
244+
245+
246+
247+
248+
249+
250+
251+
252+
253+
254+
255+
256+
257+

ReadMeCleaner.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy