Skip to content

Commit

Permalink
Add sine and cosine funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
dzibma committed Jul 4, 2015
1 parent d4abad3 commit 7364c1f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
60 changes: 60 additions & 0 deletions FuzzyMath/Functions/cos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;

namespace FuzzyMath
{
public static partial class Functions
{

/// <summary>
/// Calculates the cosine of a fuzzy number
/// </summary>
/// <param name="X">Fuzzy angle in radians</param>
public static FuzzyNumber Cos(FuzzyNumber X)
{
return FuzzyNumber.Map(X, x => Cos(x));
}

public static Interval Cos(Interval interval)
{
double a, b, x;
x = Math.Floor(interval.A / Math.PI) * Math.PI;

if (interval.Contains(x))
{
a = Math.Cos(x);
}
else
{
x += Math.PI;

if (interval.Contains(x))
{
a = Math.Cos(x);
}
else
{
a = Math.Cos(interval.A);
b = Math.Cos(interval.B);

return b > a ? new Interval(a, b) : new Interval(b, a);
}
}

x += Math.PI;

if (interval.Contains(x))
{
b = Math.Sin(x);
}
else
{
b = a > 0
? Math.Min(Math.Cos(interval.A), Math.Cos(interval.B))
: Math.Max(Math.Cos(interval.A), Math.Cos(interval.B));
}

return b > a ? new Interval(a, b) : new Interval(b, a);
}

}
}
60 changes: 60 additions & 0 deletions FuzzyMath/Functions/sin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;

namespace FuzzyMath
{
public static partial class Functions
{

/// <summary>
/// Calculates the sine of a fuzzy number
/// </summary>
/// <param name="X">Fuzzy angle in radians</param>
public static FuzzyNumber Sin(FuzzyNumber X)
{
return FuzzyNumber.Map(X, x => Sin(x));
}

public static Interval Sin(Interval interval)
{
double a, b, x;
x = Math.Floor(interval.A / Math.PI) * Math.PI + Math.PI / 2;

if (interval.Contains(x))
{
a = Math.Sin(x);
}
else
{
x += Math.PI;

if (interval.Contains(x))
{
a = Math.Sin(x);
}
else
{
a = Math.Sin(interval.A);
b = Math.Sin(interval.B);

return b > a ? new Interval(a, b) : new Interval(b, a);
}
}

x += Math.PI;

if (interval.Contains(x))
{
b = Math.Sin(x);
}
else
{
b = a > 0
? Math.Min(Math.Sin(interval.A), Math.Sin(interval.B))
: Math.Max(Math.Sin(interval.A), Math.Sin(interval.B));
}

return b > a ? new Interval(a, b) : new Interval(b, a);
}

}
}

0 comments on commit 7364c1f

Please sign in to comment.