All Questions
Tagged with numerical-methods java
20
questions
14
votes
2answers
3k views
Pi by Monte-Carlo
I was inspired by this SO post to investigate
a good Java8 way to calculate Pi based on simulation.
I used a similar task to learn about parallel programming on both CUDA,
and Intel Xeon Phi ...
10
votes
3answers
155 views
Reinventing the Math Functions
Just for practice in the mathematical side of programming, I decided to rewrite the math functions, with the addition of the root() function, which the Math library ...
9
votes
1answer
1k views
Approximating Pi, Monte Carlo integration
I wrote some code that uses Monte Carlo Integration to Approximate pi in Java and Akka. The tl;dr explanation is you can imagine throwing darts at a square with a circle inscribed inside of it. You ...
8
votes
4answers
1k views
Buffon's Needle experiment
I was working on a program that simulates the Buffon's Needle experiment. If anyone is not familiar with it, a Wiki link is provided - Buffons's Needle
The point of Buffon's experiment is to find ...
6
votes
1answer
444 views
Calculating pi to 7 significant figures without using Math.PI
I need to calculate pi to 7 significant figures in Java—without using Math.PI.
Here is the code I came up with to do that:
...
6
votes
1answer
478 views
Arbitrary Precision nth Principal Root in Java - MathCore #1
This post is the first in the MathCore series.
The next post is here: Arbitrary precision π (Circular Constant) in Java - MathCore #2
Disclaimer
My project is too big to be reviewed in a single ...
5
votes
1answer
2k views
Poker Odds Calculation with Monte Carlo
I have created an Odds Calculator in Java. The program gives me the odds, but I want to make sure that they are correct. Maybe someone can tell me a calculator I can compare my results with or knows ...
4
votes
1answer
512 views
Computing an approximate value of Pi via Monte Carlo method in Java with streams
I have this short program that attempts to compute an approximate value of \$\pi\$:
...
3
votes
4answers
2k views
Computing integer square roots in Java - follow-up
(See the previous iteration.)
My two previous methods for computing the integer square root of a number \$N\$ ran in the \$\mathcal{O}(\sqrt{N})\$ worst case time. Now I have added a method (...
3
votes
2answers
181 views
Calculating Pi with Android
I'm kind of new to Java but I am writing an Android app. Right now I'm working on an async task to calculate Pi but when I run it the memory usage increases alarmingly (+5MB per second). This one ...
3
votes
1answer
480 views
Comparing multiple arguments and returns the smallest argument
I want to see if anyone knows how to optimize the code below:
...
3
votes
1answer
805 views
Percentage based drop prize on Mob entity kill
I have created a simple percentage-based random prize drop for killing certain mobs.
A drop is basically what the player will get in return for killing a mob, as a reward.
So I have a large list of ...
3
votes
3answers
3k views
Approximating sines and cosines using up to five terms of the Taylor series
I have one programming question:
The sine and cosine of \$x\$ can be computed as follows:
\$\sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \dots\$
...
3
votes
2answers
2k views
Square root approximations, implemented two ways
Which version is more efficient in calculating the square root ?
There are 2 versions I have written to calculate square root programatically. Note reqs strictly state not using library functions ?
...
2
votes
1answer
507 views
Java Pi Calculation using an Averaged-Leibniz formula
While trying to discover a way to calculate the digits of Pi faster with the Leibniz formula for Pi, I noticed that, if I took two consecuent numbers in the series, and calculate their average, I ...
2
votes
1answer
63 views
A simple clusterness measure of data in one dimension using Java - follow-up 2
(See the previous version here.)
This time, I have encorporated all the suggestions made by Marc. Also, I changed the type of points from Double to ...
2
votes
1answer
438 views
Utility Method to find the Square root of a number
Utility to calculate the square root of a number. The method also accept an epsilon value, which controls the precision. The epsilon value could range to any number including zero. I am expecting a ...
1
vote
1answer
47 views
A simple clusterness measure of data in one dimension using Java - follow-up
(See the previous version here.)
(See the next version here.)
This time, I have incorporated all the suggestions made by Roman; my new version follows.
...
1
vote
1answer
90 views
A simple clusterness measure of data in one dimension using Java
(See the next follow-up here.)
Problem definition
Given \$X = (x_1, \dots, x_n)\$ such that \$x_1 \leq x_2 \leq \dots \leq x_n \$. Let \$x_{\min} = \min X = x_1\$, \$x_{\max} = \max X = x_n\$ and \$r =...
0
votes
1answer
130 views
Summation for π [closed]
I was going through my Java book's exercise solutions and comparing and incorporating the author's techniques into my repertoire.
Most of the time, my approach is identical to the author's. When it is ...