Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Dec 27, 2025

We've deprecated bigdecimal/ludcmp, bigdecimal/newton and bigdecimal/jacobian.
It's better to not use them in sample codes.
This might be a migration path if someone is using these deprecated files.

sample/pi.rb

Remove include PI, remove shebang.

sample/linear.rb

Use gem matrix instead of bigdecimal/ludcmp

sample/nlsolve.rb

Use gem matrix, write jacobian and newton logic inside this sample code file.
Since this code is just a sample code, error handling is omitted.

@tompng
Copy link
Member Author

tompng commented Dec 27, 2025

Comparison of sample/linear.rb

Input file

$ cat input
3
1 2 3 1
5 6 2 2
4 7 5 3

Output

$ ruby linear.rb input
Coefficient matrix and constant vector.
0) 1 2 3 1
1) 5 6 2 2
2) 4 7 5 3
Answer(x[i] & (A*x-b)[i]) follows
x[0]=-0.2666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666664e0  & 0.16e-99
x[1]=0.5333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333332e0  & 0.64e-99
x[2]=0.6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666672e-1  & 0.4e-99

Output in master branch

$ git switch master   
$ ruby linear.rb input
'bigdecimal/ludcmp' is deprecated and will be removed in a future release.
Coefficient matrix and constant vector.
0) 1 2 3 1
1) 5 6 2 2
2) 4 7 5 3
Answer(x[i] & (A*x-b)[i]) follows
x[0]=-0.2666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666664e0  & -0.2e-99
x[1]=0.5333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333332e0  & 0.0
x[2]=0.6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666672e-1  & 0.0

@tompng
Copy link
Member Author

tompng commented Dec 27, 2025

# sample/nlsolve.rb
...
ans = nlsolve(initial_value, prec: 100) {|x| func(x) }
diff = func(ans).map {|v| v.mult(1, 10) }
p(ans:)
p(diff:)
{ans: [0.1218245836551854221294816349945599902708230426322897706646893441528370772984244758379821844214668379e1, 0.7182458365518542212948163499455999027082304263228977066468934415283707729842447583798218442146683795e0]}
{diff: [-0.1137205797e-98, -0.1372057968e-99]}

Diff is small enough, so the calculation is working.

I found that deprecated bigdecimal/newton calculates only 50 digit when eps=1e-100. This might be a bug, but no plan to maintain nor fix it.

@tompng tompng force-pushed the sample_without_deprecated branch from 212d311 to 74197be Compare December 27, 2025 15:53
@tompng tompng changed the title Sample without deprecated modules Sample code without deprecated modules Dec 27, 2025
@tompng tompng merged commit 1350fa5 into ruby:master Dec 27, 2025
87 of 89 checks passed
@tompng tompng deleted the sample_without_deprecated branch December 27, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant