Code Monkey home page Code Monkey logo

intsharp's Introduction

IntSharp

A rigorous interval arithmetic library for .NET

Sample usage

This section will give some examples on how to use IntSharp. For a quick introduction to interval arithmetic, take a look at the corresponding Wikipedia article. For further, advanced functions of IntSharp, it is recommended to study the corresponding unit tests. They cover almost every aspect of the implementation and give insights on how to use specific features.

  • Create intervals with one of the several factory methods and calculate with them:
var i1 = Interval.FromInfSup(3.2,7); // [3.2 , 7]
var i2 = Interval.FromMidRad(4.8,2.2); // [2.6 , 7]
var i3 = Interval.FromDoublePrecise(9.34); // [9.34 , 9.34]

var res = (i1 * i2 + i3) / 2;
  • Make verified calculations with included error propagation. No approximations, no derivations.
// Init interval with MidRad factory
var height = Interval.FromMidRad(3.8, 0.2);

// Init interval with InfSup factory
var accelerationOfGravity = Interval.FromInfSup(9.8, 9.82);

// Calculate the verified result
var velocity = Math.Sqrt(2 * height * accelerationOfGravity);
// = [8.4 , 8.863]
  • Solve determined or overdetermined linear equation systems and obtain verified results:
// Init items for the matrix A.
var aItems = new[,]
{
    {Interval.FromMidRad(2,0.2), Interval.FromDoublePrecise(1)},
    {Interval.FromMidRad(7,0.2), Interval.FromDoublePrecise(1)}
};

// Init items for the rhs vector b.
var bItems = new[]
{
    Interval.FromMidRad(4,0.2),
    Interval.FromMidRad(1,0.2)
};

// Init matrix A and vector b.
var a = new IntervalMatrix(aItems);
var b = new IntervalVector(bItems);

// Solve the system with or withought error weighing:
var result = LinearEquationSystem.Solve(a, b);

Find verified enclosures of a function's root:

private static Interval MyTestFunction(Interval x)
{
    return 2 * Math.Pown(x, 3) - 9;
}

private static Interval MyTestDerivative(Interval x)
{
    return 6 * Math.Pown(x, 2);
}

public void FindTestRoot()
{
    var myTestRange = Interval.FromInfSup(0, 100);
    var root = RootFinding.FindRoot(
        MyTestFunction, 
        MyTestDerivative,
        myTestRange);
}

Quickstart for Mono (Linux)

  • Clone or download IntSharp and change to it's root directory
git clone https://github.com/selmaohneh/IntSharp.git
cd /path/to/IntSharp
  • Install the required packages mono-complete and nuget from your distribution package manager.
apt-get install mono-complete nuget
mono /path/to/NuGet.exe update -self
mono /path/to/NuGet.exe install NUnit            -OutputDirectory packages -Version 3.7.1
mono /path/to/NuGet.exe install NUnit.Console    -OutputDirectory packages -Version 3.6.1
mono /path/to/NuGet.exe install MathNet.Numerics -OutputDirectory packages -Version 3.19.0
  • Build the project:
xbuild IntSharp.sln
  • Finally, run the tests:
mono packages/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe \
  IntSharpTests/bin/Debug/IntSharpTests.dll --noresult
NUnit Console Runner 3.6.1
Copyright (C) 2017 Charlie Poole

Runtime Environment
   OS Version: Linux 4.4.74.18
  CLR Version: 4.0.30319.42000

Test Files
    IntSharpTests/bin/Debug/IntSharpTests.dll


Run Settings
    DisposeRunners: True
    WorkDirectory: /workspace/IntSharp
    ImageRuntimeVersion: 4.0.30319
    ImageTargetFrameworkName: .NETFramework,Version=v4.6.1
    ImageRequiresX86: False
    ImageRequiresDefaultAppDomainAssemblyResolver: False
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Passed
  Test Count: 93, Passed: 93, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2017-07-09 21:31:31Z
    End time: 2017-07-09 21:31:32Z
    Duration: 1.041 seconds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.