Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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

26 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7
votes
0answers
2k views

constexpr Sin Function C++ 14

I have written a constexpr sin function using c++14 and would like to know what I can do to improve it. I am trying to balance code clarity/maintainability with ...
6
votes
0answers
618 views

Recursive factorial calculations in Rust

I am trying to calculate very large factorials. I am looking to speed it up as 10000! takes approximately a minute and a half. ...
6
votes
0answers
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 ...
5
votes
0answers
130 views

Kernel density regression in Julia

Here is a naive implementation of a kernel density regression algorithm in Julia. The code works, but there is quite a bit of room for improvement though. First, there is not an optimal bandwidth ...
4
votes
0answers
107 views

Volatility updating with Heston-Nandi model

I'm trying to program a volatility updating rule using iteration. I start with the well-known Heston-Nandi model where the returns dynamics are: $$ \left\{ \begin{array}{rcl} R_{t+1} &=&...
4
votes
0answers
2k views

Satellite orbit simulation in Matlab using Runge Kutta 4

I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it. fx.m file: function v = fx(t,x,vx) v = vx; ...
3
votes
0answers
49 views

Magic Square with Five Methods (Python)

Problem Write a program to return a boolean if an input grid is magic square. A magic square of order \$N\$ is an arrangement of \$N^2\$ distinct integers in a square such that the \$N\$ numbers in ...
3
votes
0answers
61 views

Optimising multiplication of matrix rows with matrix slice/page

I've recently vectorized most of the code for an optimization problem but this one still eludes me. As the procedure and not the actual values are important here, I have replaced the original matrices ...
3
votes
0answers
53 views

“Academic interest” implementation of a Finite State Machine

Context I'm playing around the concept of a Finite State Machine. While I understand the basic principles behind it, I want to implement a simple, yet generic class which could be reused in the ...
3
votes
0answers
103 views

Gradient computation in JavaScript

I'm working with some math-heavy code in JavaScript. I just realized that there's a render that currently takes about 30 minutes. 95% of that time is spent in a single ~40 line function that I've ...
3
votes
0answers
809 views

Computing intersection of 2D infinite lines

I wrote a small program to compute intersection of 2D infinite lines using Boost Geometry A line is defined by two points in Line class. The ...
3
votes
0answers
70 views

Slow multiplication in a modulo

I am willing to get a linear output of a product in a ring Z/nZ For that I have successfully implemented a code that does a Product in a modulo However, it is not optimized to output the steps ...
3
votes
0answers
185 views

Calculating continued fraction expansions (without requiring arbitrary precision decimals)

I'm writing a program that will compute a continued fraction expansion of a number. I've been learning Racket/Scheme for a few weeks and I wanted to see what I can do better. Usage: This program ...
2
votes
0answers
92 views

Shutting down all lamps with minimum number of switch presses

I found an optimization problem written in Finnish but I will translate it into English. The following is an example case. I have \$n=120\$ lamps in a circle, and enumerated by \$L_1,…,L_{120}\$. ...
2
votes
0answers
117 views

Python RSA/DSA File Cryptography, Key Generation, Key Protection

I have forked a previous version of my script, critiqued here: Generate public/private keys, encrypt, decrypt, sign, verify This program allows you to encrypt and decrypt raw files using RSA keys ...
2
votes
0answers
312 views

Matrix inverse by elimination

Because I had trouble in finding a reliable source on the internet for the matrix inverse algorithm using Gaussian elimination, I wrote one myself. Matrix.h ...
2
votes
0answers
89 views

Improved Atkin-Bernstein sieve for generating primes

This is a class from my personal code library, and from a package which deals with integer sequences. It implements an interface ...
2
votes
0answers
296 views

Factoring a polynomial with integer coefficients

I haven't programmed in a while and need to improve my code in any way possible: efficiency, readability, etc. This program is for getting integer coefficients of any polynomial and factoring: ex. $$ ...
2
votes
0answers
117 views

Roots of Unity in R

I have a paper on the definition of (i) available here. I was curious about the simultaneous real numbers associated with the roots of unity, and noticed there was not a routine in R. I have this ...
1
vote
0answers
52 views

Solidity: verifying primality certificates, bounty for large primes

This is my first smart contract, and it isn't finished yet, but the remaining bits are complicated enough that I'd like to make sure I'm on the right track first. My concerns are: At line 117, is the ...
1
vote
0answers
454 views

Python palindrome function; is it possible to write it without using string conversion?

I hope this question is okay to ask on Code Review; this is a little function I wrote in Python 2.7.12 that checks if a number is a palindrome. It works fine but I'd like to know if there is a purely ...
1
vote
0answers
134 views

Quadratic equation solver in Ruby

I wrote a simple quadratic equation solver with Ruby to help me solve quadratic equations. Please tell me what I did right or wrong, and what I can do to improve it. ...
1
vote
0answers
132 views

Determine amicable pairs within confines of Θ(n)

I had to implement a program that takes a number userNum from the user and finds all perfect numbers and pairs of amicable numbers within the range \$\lbrace 2, \...
1
vote
0answers
726 views

Snell's law using Zoeppritz equation by matrices

I have created the following code to calculate Snell's law angles, based on Zoeppritz equations on complex plane. The code works, seems it is returning valid values, but after all the code just looks ...
1
vote
0answers
150 views

Find Euler totient of a large range of numbers

(Euler Totient Function) Is there any way to make it faster/better in asymptotic complexity? ...
1
vote
0answers
100 views

Naive Grouping for Factorization

UPDATE: I have posted this question on math.se along with the identification of a new relationship to lattice points on hyperbola. I have a naive grouping method for factorization. I am curious as ...