mathpack 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10ff066c9adc6d22256567faf50bb86bfa41b919
4
- data.tar.gz: dd387c24f4f687771eed4119b9d4e843be181e2b
3
+ metadata.gz: 3d83a43c2f840fff63926eec5d9548e0f5051fcd
4
+ data.tar.gz: 949637138199c144e04ce0ed085d8b249d40a4dc
5
5
  SHA512:
6
- metadata.gz: 6a4147c4f2be3f383dd001c9092e61ee127bb5cfbfd7300ec58ad4fa430b91dc358f561440fa70c4f1e86e1749519a93e332d2a1c04e27e112cc0547d5049fcb
7
- data.tar.gz: fb1dfcefe66bd0dc9e8496353d57eb10288b394551cdcf07d2f83a5ff32e85dfac65b752f2ffa128346cfafbfa31b6a57dd13b15f42b1b87a287f5def36ea707
6
+ metadata.gz: 257fe6c5dac7b567ead47d8546aebd2f945a6d32a4cd87f7fb4e14ad4420eadf026a2139dc8770bf8caee294cb946beb250bb80136ce8b9947954ce8f6f2c5d9
7
+ data.tar.gz: a18a58ed4da327ffdd05f92d88c5f11940346273a16cc2b3d5b33a53f5b9c973ff9d57eee1cb0fc466ce08f46aa610fc7186a901cca741d92476981201ca01a7
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  language: "ruby"
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.2
6
5
  - 2.1.3
7
6
  - 2.2.0
7
+ - 2.3.0
8
8
  script: "bundle exec rspec"
9
9
  notifications:
10
10
  email: false
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rspec', group: :test
4
+ gem 'pry-rails', group: :development
5
+
4
6
  gemspec
data/README.md CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
26
26
  - **Approximation**. Allows to approximate table and analytical functions by polynom
27
27
  - **NonlinearEquations**. Solves unlinear mathematical equations
28
28
  - **IntegralEquations**. Solves integral second order Fredholm and Volter equations
29
+ - **DifferentialEquations**. Solves system of differential equations with left border initial conditions
29
30
  - **Integration**. Integrates functions
30
31
  - **IO**. Prints data
31
32
  - **Functional**. Lambda functions
@@ -197,6 +198,32 @@ Mathpack::IntegralEquations.solve_volter_2(from: 0.0, to: 1.0, lambda: 0.5, eps:
197
198
  #=> {:x=>[0.0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375, 1.0], :f=>[1.0, 1.0644951210235056, 1.1331511709098798, 1.2062365414157485, 1.2840369296892897, 1.3668564541117094, 1.455018842114489, 1.5488686946157586, 1.6487728320186184, 1.755121727033003, 1.868331029922017, 1.9888431921348702, 2.117129194673052, 2.2536903879456665, 2.3990604503055315, 2.5538074729214233, 2.718536179135541]}
198
199
  ```
199
200
 
201
+ ## DifferentialEquations
202
+ #### solve_cauchie_system(params={})
203
+ returns solution of differential equations system as a hash of nodes and values arrays for each function. For example, { x: [], u1: [], u2: [], ... }
204
+ ##### Parameters
205
+ - ***from*** - left border
206
+ - ***to*** - right border
207
+ - ***system*** - array of lambdas representing each row of system
208
+ - ***y0*** - array of values of derivatives on left border. Starts with first derivative
209
+ - ***eps*** - accuracy
210
+
211
+ ### Usage
212
+ Let we have following system of differential equations
213
+
214
+ ![equation](http://latex.codecogs.com/gif.latex?%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D%20%7Bu_%7B1%7D%7D%27%3Du_%7B2%7D%26%26u_%7B1%7D%281%29%3D1%20%5C%5C%20%7Bu_%7B2%7D%7D%27%3D%5Cfrac%7B1%7D%7Bx%5E%7B2%7D%7Du_%7B1%7D-%5Cfrac%7B1%7D%7Bx%7Du_%7B2%7D+3%26%26u_%7B2%7D%281%29%3D1%20%5Cend%7Bmatrix%7D%5Cright.)
215
+
216
+ where
217
+
218
+ ![equation](http://latex.codecogs.com/gif.latex?1%5Cleq%20x%5Cleq%202)
219
+
220
+ If you want to solve this system with accuracy **1e-6**, you should call
221
+ ```ruby
222
+ cauchie_problem = [ ->(x, u1, u2) { u2 }, -> (x, u1, u2) { - 1.0 / x * u2 + 1.0 / x**2 * u1 + 3.0 }]
223
+ Mathpack::DifferentialEquations.solve_cauchie_system(from: 1.0, to: 2.0, eps: 1e-6, system: cauchie_problem, y0: [1.0, 1.0])
224
+ #=> {:x=>[1.0,..., 2.0], :u1=>[1,...], :u2=>[1,...] }
225
+ ```
226
+
200
227
  ## SLE
201
228
  #### solve(params = {})
202
229
  returns solution of system of linear equations.
@@ -60,7 +60,13 @@ module Mathpack
60
60
  end
61
61
  break if is_finished
62
62
  end
63
- { x: Mathpack::Approximation.generate_nodes(from: params[:from], to: params[:to], step: step), y: u_next.first }
63
+ generate_result(params, step, u_next)
64
+ end
65
+
66
+ def self.generate_result(params, step, u)
67
+ result = { x: Mathpack::Approximation.generate_nodes(from: params[:from], to: params[:to], step: step) }
68
+ u.each_index { |i| result[:"u#{i + 1}"] = u[i] }
69
+ result
64
70
  end
65
71
  end
66
72
  end
@@ -1,3 +1,3 @@
1
1
  module Mathpack
2
- VERSION = '0.4.8'
2
+ VERSION = '0.4.9'
3
3
  end
@@ -8,7 +8,7 @@ describe 'DifferentialEquation' do
8
8
  cauchie_problem = [ ->(x, u1, u2) { u2 }, -> (x, u1, u2) { - 1.0 / x * u2 + 1.0 / x**2 * u1 + 3.0 }]
9
9
  result = Mathpack::DifferentialEquations.solve_cauchie_system(from: 1.0, to: 2.0, eps: eps, system: cauchie_problem, y0: [1.0, 1.0])
10
10
  correct_result = Mathpack::Approximation.fill_f(result[:x]){ |t| t**2 - 0.5 * t + 1.0/(2.0 * t) }
11
- expect(Mathpack::IO.count_diff(result[:y], correct_result) <= eps).to eq(true)
11
+ expect(Mathpack::IO.count_diff(result[:u1], correct_result) <= eps).to eq(true)
12
12
  end
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxmilan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-03 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.4.3
97
+ rubygems_version: 2.4.8
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Summary