The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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?)

432 questions
Filter by
Sorted by
Tagged with
93 views

Find all subsets of a vector that sum up to another vector

I'm looking for a way to make my code more simple. This code takes a list of vectors and returns all subset of that list that sum up to another vector. For example: ...
5k views

Fibonacci generator with Golang

This is my Fibonacci generator: package main import "fmt" func main() { for i, j := 0, 1; j < 100; i, j = i+j,i { fmt.Println(i) } } It's ...
1k views

Python — polynomial operations class

This Python class takes a GF2 (finite field mod 2, basically binary) polynomial in string form, converts it to a binary value, then does arithmetic operations, then converts the result back into a ...
1k views

Is my 4x4 matrix multiplication on a 1D float array correct?

I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D ...
273 views

Summing 2D NumPy array by multiple labels

Each element of the array is a coordinate (x, y). Each coordinate has two labels. Goal: sum the elements that have the same two labels. How can ...
89 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 / ...
3k 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 ...
12k 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 "...
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,...
3k 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 ...
4k 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: ...
3k views

...
939 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 ...
1k 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 ...
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. ...
99 views

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. ...
2k views

...
515 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: ...
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 ...
278 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 ...
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 ...
474 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 ...
334 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? ...
233 views

Simple recursive Summing program

Any tips on how to improve this simple recursion program? ...
16k 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 ...
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 ...
591 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 ...
113 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 ...
568 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. ...
225 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 - ...
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 ...
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 ...