Questions tagged [mathematics]
For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?)
627
questions
1
vote
1
answer
104
views
Is this routine for determining the epsilon of a Double 100% valid?
This algorithm is intended to determine the epsilon of a given double precision number. As numbers increase in value, their accuracy decreases. This algorithm will return the smallest increment / ...
2
votes
1
answer
4k
views
Generating Pandigital Numbers
A Base10 Pandigital Number is a number which uses all the digits 0-9 once:
1234567890
2468013579
etc...
My naive solution was just to use a bunch of nested loops to do this but it's quite slow. And ...
10
votes
5
answers
14k
views
Polynomial program
The program basically takes a polynomial and does some simple calculations with it.
With a couple of hours of work I managed to get my first console application to work (aside from the obligatory "...
4
votes
1
answer
2k
views
Truncating an integer from left to right and right to left
Project Euler problem 37 says:
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797,...
18
votes
2
answers
4k
views
GCD/LCM calculator in x86 NASM assembly
After creating a similar program in C++, I've decided to try to write it in x86 assembly language (the type of assembly I was taught in college).
I'd like to receive feedback regarding syntax and ...
4
votes
1
answer
5k
views
Integration of data using Simpson's rule
I wrote a Python program that performs an integration of data using Simpson's rule. The program takes the areas to be integrated from a foo.ref file, with the following syntax:
...
6
votes
2
answers
3k
views
12
votes
1
answer
1k
views
Parsing numbers from equations into strings
This is my first code in C++. Since I'm new to the language, I'm just looking for pointers on what can be made better. I tried to cut out unnecessary stuff, but there are some comments in there. I ...
2
votes
3
answers
2k
views
Solving Diophantine equations
I have a project for solving Diophantine equations, where a solution exists if
$$A^5 + B^5 + C^5 + D^5 + E^5 = F^5$$
where \$0 < A <= B <= C <= D <=E <= F <= N\$
The program ...
11
votes
3
answers
4k
views
Determining Pythagorean triples based on the hypotenuse
Below is my written code to determine if, based on the hypotenuse, a Pythagorean triple is possible, and what are the lengths. I was wondering if there is a more efficient way of doing so.
...
2
votes
2
answers
109
views
Adding matrices
This is what the code should do:
Check if the first dimensions and the second dimensions of each 2-dimensionalarray are the same. If they are not the same, then return a 0x0 2-dimensional array. ...
24
votes
5
answers
2k
views
7
votes
1
answer
551
views
Optimizing code from spectral subtraction algorithm
This is part of the code from a spectral subtraction algorithm. I'm trying to optimize it for Android.
Matlab code:
...
7
votes
5
answers
20k
views
Calculating nth power of x
I have written this code which precisely calculates the nth power of x by a recursive method.
I compared my program with Java's pow(double, double) function, and ...
8
votes
1
answer
343
views
Computing a Discrete Cosine Transform matrix
I'm learning Haskell and I needed to work with discrete cosine transform matrices, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix.
The elements of ...
4
votes
5
answers
5k
views
How does this quadratic formula program look?
I'm new to Java and this is my first program. I'm trying to verify that my thought processes are good.
Let me know of any improvements infor the code, whether it's too few/too many comments, poorly ...
5
votes
2
answers
557
views
High performance exponential of a skew Hermitian matrix in Fortran 95
I'm new to Fortran, and this is pretty much my first escapade. Below is a function that I wrote which relies on calls to LAPACK. The function is sat in a module with some other functions and works ...
2
votes
1
answer
502
views
Runge-Kutta 2nd order of differential equations
Could I improve this somehow (not numerically, just C-wise)? Do I need to allocate the array since I am returning it and not just using it inside the function?
...
4
votes
1
answer
243
views
Simple recursive Summing program
Any tips on how to improve this simple recursion program?
...
15
votes
5
answers
22k
views
Sine function in C / C++
Due to software constraints, I cannot use the standard libraries, cmath, algorithm, templates, inline, or boost. I am also using ...
6
votes
3
answers
1k
views
Print pair representing objects from sequence of nonnegative integer pairs
There are some things I am not sure of from a professional standpoint about the "correct" way to write C++ code. I have been looking through source code produced by various opensource projects, as ...
6
votes
4
answers
607
views
Compute random triplets of float pairs and average area of generated triangles
I am trying to get in a lot of practice for interviews so I am trying to write as much code as possible, and getting feed back from excellent programmers like "you". Can I get some general feed back ...
1
vote
1
answer
128
views
Function that multiplies all numbers between "a" and "b" with do loop
I'm making a function that multiplies all numbers between an "a" input and a "b" input with do loop. If you please, check my function and say what's wrong since I ...
7
votes
2
answers
608
views
Find number of divisors for integer and sum of integers
This function computes and returns the number of divisors an integer has. But it is very slow and I believe it can be optimized for speed.
...
1
vote
1
answer
247
views
Compute e using Euler's expansion
Given the following task:
Exercise 1.38. In 1737, the Swiss
mathematician Leonhard Euler published
a memoir De Fractionibus Continuis,
which included a continued fraction
expansion for e - ...
6
votes
2
answers
7k
views
Cube root (Newton's method)
Newton's method for finding cube roots states that for any given \$x\$ and a guess \$y\$, a better approximation is \$\dfrac{(\dfrac{x}{y^2} + 2y)}{3}\$.
What do you think of this code for finding a ...
6
votes
2
answers
661
views
Determining if f(n) = n^2 + 3n + 5 is ever divisible by 121
Given the following problem:
It is conjectured that for any \$n > 0\$, \$n^2 + 3n + 5\$ is never
divisible by 121. Test this conjecture for \$n = 1,2,...,9999,10000\$.
I wrote the following ...