Coder Social home page Coder Social logo

silicium's Introduction

Gem Version Build Status Maintainability Test Coverage

Silicium

Ruby Math Library written as exercise by MMCS students.

Installation

Add this line to your application's Gemfile:

gem 'silicium'

And then execute:

$ bundle

Or install it yourself as:

$ gem install silicium

Usage

Numerical integration

Library Numerical integration includes methods for numerical integration of functions, such as 3/8 method, Simpson method, left, right and middle rectangle methods and trapezoid method.

Each function accepts 4 parameters, such as left and right integration boundaries, default accuracy of 0.0001 and the function itself. Example: three_eights_integration(4, 5, 0.01) { |x| 1 / x } or three_eights_integration(4, 5) { |x| 1 / x }

For example, to integrate 1 / x in between [4, 5] using the 3/8 method, you need to use: NumericalIntegration.three_eights_integration(4, 5) { |x| 1 / x }

using the Simpson's method: NumericalIntegration.simpson_integration(4, 5) { |x| 1 / x }

using the left rectangle method: NumericalIntegration.left_rect_integration(4, 5) { |x| 1 / x }

using the right rectangle method: NumericalIntegration.right_rect_integration(4, 5) { |x| 1 / x }

using the middle rectangle method: NumericalIntegration.middle_rectangles(4, 5) { |x| 1 / x }

using the trapezoid method: NumericalIntegration.trapezoid(4, 5) { |x| 1 / x }

Theory of probability

Combinatorics

Module with usual combinatorics formulas

    factorial(5) # 5! = 120
    combination(n, k) # C(n, k) = n! / (k! * (n-k)!)
    arrangement(n, k) # A(n, k) = n! / (n - k)!

Module Dice

Module describing both ordinary and unique dices

You can initialize a Polyhedron by two ways

first: by number - Polyhedron.new(6) - creates polyhedron with 6 sides [1,2,3,4,5,6]

second: by array - Polyhedron.new([1,3,5]) - creates polyhedron with 3 sides [1,3,5]

class Polyhedron
    csides # sides number
    sides  # array of sides
    throw # method of random getting on of the Polyhedron's sides

Example

d = Polyhedron.new(8)
d.csides # 8
d.sides # [1,2,3,4,5,6,7,8]
d.throw # getting random side (from 1 to 8)

d1 = Polyhedron.new([1,3,5,6])
d1.csides # 4
d1.sides # [1,3,5,6]
d1.throw # getting random side (from 1 or 3 or 5 or 8)

Class PolyhedronSet

You can initialize PolyhedronSet by array of:

Polyhedrons

Number of Polyhedron's sides

Array of sides

class PolyhedronSet
    percentage # hash with chances of getting definite score
    throw   # method of getting points from throwing polyhedrons
    make_graph_by_plotter # creating graph introducing chances of getting score

Example

s = PolyhedronSet.new([6, [1,2,3,4,5,6], Polyhedron.new(6)]) 

s.percentage # {3=>0.004629629629629629, 4=>0.013888888888888888, 5=>0.027777777777777776, 6=>0.046296296296296294, 
              # 7=>0.06944444444444445, 8=>0.09722222222222222, 9=>0.11574074074074074, 
              # 10=>0.125, 11=>0.125, 12=>0.11574074074074074, 13=>0.09722222222222222, 14=>0.06944444444444445, 
              # 15=>0.046296296296296294, 16=>0.027777777777777776, 17=>0.013888888888888888, 18=>0.004629629629629629}    

s.throw   # getting random score (from 3 to 18)

s.make_graph_by_plotter(xsize, ysize) # creates a graph in 'tmp/percentage.png'

TODO: Write usage instructions here

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mmcs-ruby/silicium. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Silicium project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

silicium's People

Contributors

dmitry-drozdov avatar dobrzhanskij avatar dr0bash avatar dr3amy avatar drkazeev avatar efedra avatar immoraly avatar innominat0 avatar ivolnoboi avatar kpdzhnv avatar lereena avatar lovedud avatar luckynatrium avatar mihaxxx avatar monluxfer avatar msserd avatar murih avatar nechushkingit avatar robertovna avatar robolabgs2 avatar semyondv avatar stas1f1 avatar tetrergeru avatar ursasm avatar violetta0012 avatar vl-tershch avatar vovacolt avatar wolwer1ne avatar

Watchers

 avatar

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.