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

Filter by
Sorted by
Tagged with
1
vote
0answers
26 views

Integrate a normal map via a 2D gradient field

This code transforms a normal map into a 2D gradient field and then iteratively integrates it to a likely solution. I don't have a lot of experience with C++/CUDA yet and would appreciate some advice ...
4
votes
4answers
753 views

Count numbers that are the sum of three perfect cubes

From numbers from 1 to 100, count the numbers where the following equation is satisfied with 1 <= a <= 100, 1 <= b <= 100, and 1 <= c <= 100: $$a³ + b³ + c³$$ I have this: ...
-2
votes
0answers
25 views

How to find solution to an equation in Java? [closed]

So, basically I wanna know how to get solution to an equation in Java. For example, there will be a lot of equations solutions to which will not be of an exact form we know. For example, the equation ...
-3
votes
0answers
28 views

Random Number Calculator [closed]

I made these two random number generators, but I have some trouble getting the random results to add to one another over a third button. The result should be shown inside the same window in another ...
6
votes
4answers
750 views

Converting lengths and weights using functions in C++

Question is: Write a program that asks the user if he or she wants to convert lengths or weights. If the user chooses lengths, then the program asks the user if he or she wants to convert from feet ...
0
votes
0answers
27 views

Haskell proof checker for FOL with equality

Is this a correct implementation in Haskell of a proof checker for first order logic with equality? I am most interested in if it is correct, and if the functions can be made clearer. I would like it ...
3
votes
1answer
89 views

(Google Foobar XOR Checksum Challenge) How do i optimize this function to run for much larger values?

I wrote a function that accepts 2 integers start and length as input and returns the bitwise XOR of certain numbers as described below: ...
0
votes
1answer
60 views

Generating floats from integers

I wanted to make an algorithm that is a counter-example of Cantor's diagonalization argument. Given an integer, this Python code will produce a unique rational number. Fed the sequence of positive and ...
5
votes
1answer
57 views

Exploring the space of 8 parameters of a physics problem to then be evaluated in ODE integrator as LSODA millions of times, efficently

there's a function in one of the scripts I've been working on that I really want to improve. Disclaimer: Being honest, I'm not really very good at programming but I've been learning day to day and it'...
2
votes
0answers
33 views

Maximizing Efficiency of Collatz Conjecture Program Python

My question is very simple. I wrote this program for pure entertainment. It takes a numerical input and finds the length of every Collatz Sequence up to and including that number. I want to make it ...
4
votes
1answer
59 views

Find the mean magnitude of values inside unit circle

I'm fairly new to Python and am exploring how to fix functions and make code 'more effective and readable'. As a first step, I would want to try to make shorter snippets of code here - for example by ...
2
votes
1answer
64 views

Cholesky decomposition

This code is Cholesky decomposition in numerical linear algebra. ...
2
votes
1answer
33 views

Intersection of 2D vector equation straight lines

I know the vectors that describe two lines, $$\mathbf{a} + \lambda\mathbf{d}$$ and $$\mathbf{b} + \mu\mathbf{d'}$$ I've written a JavaScript function to get the coordinates of the point of ...
2
votes
1answer
91 views

Simple Lagrange interpolation

I wrote a Lagrange polynomial interpolation class. It works fine. At the beginning some definitions: $$ \begin{align} &nodes:\qquad x_0, \dots, x_n \\ &values:\qquad f(x_0), \dots, f(x_n) \\ &...
6
votes
2answers
304 views

Writing a C++ Matrix class

I am refreshing my C++ programming skills, and I'm currently reading the book C++ 17 by Ivor Horton. The idea is to code some naive implementations of numerical algorithms (Root finding, solving a ...
3
votes
1answer
55 views

Convert number from old range to new numeric range

I have a function that takes a specific number and a range, and re-scales it to the corresponding number in a different range. ...
0
votes
3answers
71 views

Print greatest factor if it is same for both numbers

Take input n1 and n2 and check if they have the same greatest factor. If they do, print that factor. If they don't, print "No". example: input: 6 9 output: 3 input: 15 27 output: No ...
3
votes
2answers
96 views

Python program to find all possible ways an integer num can be expressed as sum of integers between 1 and lim

This is a Python program that finds all possible ways a positive integer num can be expressed a sum of a number of integers between 1 and ...
4
votes
2answers
86 views

find closest distance between two numbers (looking for improvement)

Let's say I have a number set like below // 1,2,3,4,5,6,7,8 Now I want to go from 2 to 5. ...
3
votes
3answers
198 views

Third and second degree polynomial equation solver in C++

I'm quite new to C++, so as a beginner's project I decided to create a program that can solve second degree polynomials and (some) cubics using this lengthy formula I had found online. I would love to ...
6
votes
1answer
372 views

Calculating decimal places of pi in Python

I have written this small program in Python to calculate decimal places of \$\pi\$. I tried to code it as readably as possible, but since this is a bit calculation heavy, it is reasonable to think ...
1
vote
2answers
57 views

Ask 2 terms from user and add them

I'm making a program that can add 2 terms that the user types. I think I've got identifying or evaluating the terms down. I used classes because I just recently learned it and I also heard it was good ...
3
votes
0answers
65 views

converting from byte arrays to strings of integers, and back

I have this code to go from an array of bytes (arbitrarily long) to a "bigint" string (really, an arbitrarily long string composed of integers 0-9), and go from that long integer string into ...
0
votes
0answers
89 views

2D Discrete Fourier Transform using Fortran

I am solving the 2D Wave Equation using Fourier Transform. The Discrete Fourier Transform (and the inverse also) is done inside the kx-loop and ...
3
votes
1answer
160 views

Permutation function for a math library in C++

Continuing the code for combinatorics library, adding the definition of ⁿPᵣ. This is an extract from a larger codebase. Is there any way to limit the code of gcd()...
10
votes
5answers
2k views

Sine function calculated via look-up table and linear interpolation

I have been attempting to implement a function calculating values of the sine function. I know that there are several similar threads regarding this topic but my goal was to try to implement such ...
2
votes
1answer
92 views
1
vote
1answer
33 views
4
votes
1answer
92 views
0
votes
3answers
80 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
1
vote
3answers
68 views

Recursive power (mathematical operation) function in C

How to make a C recursive exponentiation (power) function better? I developed a pretty simple (yet decent, imo) power function for the sake of learning. I'm not quite trying to compete with ...
0
votes
0answers
27 views

Three Project Euler solutions in the D programming language

I recently wrote some programmes in D language to solve the first ten problems on Project Euler, but I'll be discussing only three of them (but you're free to check out my GitHub repo with all ten ...
1
vote
0answers
41 views

Applied Solution Based On Polya Enumeration Theorem

Problem A function solution(w, h, s) that takes 3 integers and returns the number of unique, non-equivalent configurations that can be found on a grid w blocks wide, h blocks tall and s possible ...
1
vote
1answer
53 views

Find circles for `f(z, c) = z ^ 2 + c` of length 6 in rational numbers

I've found pretty simple problem on Numberphiles channel: suppose we have a recursive function $$ \begin{equation} \begin{split} f_0 &= Z ^ 2+ C \\ f_i &= f_{i-1}^2 + C \; | \; i = 1 \dots \...
0
votes
0answers
65 views

Transform inertia tensor

I am trying to translate book: Game Physics Engine Development by Ian Millington to DirectXMath and faced with the code wich transform inertia tensor. Is it right to convert code from book like that: ...
4
votes
2answers
254 views

Mean difference calculator for any int combination

What it does Calculates the mean difference for a list of any combination of ints (I think). What I want to know The only other way I can think of doing this is using recursion. I’d like to know if ...
3
votes
1answer
368 views

Python code to find greatest common divisor of multiple numbers

Hmm, I know this has been implemented countless times, and Python 3.9.5 math standard library has a built-in gcd() method that ...
8
votes
5answers
4k views

A math engine with support for complex numbers, calculus, and fractions

I've been creating a math engine in C++. I have decided now is a good time to ask for feedback from the community. Right now the main "good" things it has is complex numbers, calculus and a ...
4
votes
2answers
61 views

Formula filler and calculator

So I made this script for my calculator, so that I can just write whatever formula I want and the calculator would just ask for the missing pieces to do the calculations. I made it so that it would be ...
3
votes
2answers
37 views

Runge Kutta 2 Python ODE fluid flow

I am trying to solve a set of differential equations in x,y,z, I have made simple kutta 2 code in python before but not with 3 variables. I am not sure if what i have done is an acceptable way to ...
2
votes
1answer
130 views

Implementation of the square root for real time application

For the real time control software I need square root calculation. I have heard that the sqrt function from the standard library isn't good choice due to the unpredictable number of iterations used ...
14
votes
1answer
423 views

C++ class to create and evaluate Chebyshev approximations of arbitrary functions

I recently needed to create a function to approximate a complex trigonometric function on an embedded system without a floating point unit and without a fast trigonometric library. So I pulled out my ...
0
votes
1answer
69 views

Sum of fractions

Objective: Create a function to sum a list of fractions (represented as pairs) Rules Only Prelude functions allowed Notes I was debating if I should create a ...
1
vote
1answer
580 views

Lo Shu Magic Square (Python)

I wrote a python program to find if a matrix is a magic square or not. It works, but I can't help feeling like I may have overcomplicated the solution. I have seen other implementations that were a ...
2
votes
2answers
161 views

Finding distance between vectors of matrices

So here is the problem: Given 2D numpy arrays 'a' and 'b' of sizes n×m and k×m respectively and one natural number 'p'. You need to find the distance(Euclidean) of the rows of the matrices 'a' and ...
3
votes
1answer
80 views

Implementation of the basic matrix operations for embedded application in C++

I have been developing a control software in C++ and for implementation of the control algorithms I need basic matrix operations like addition, subtraction, multiplication and multiplication by scalar....
8
votes
5answers
2k views

Implementation of the trigonometric functions for real time application

I have been developing a real time application in C and I need to calculate sine and cosine of a given angle in radians. In respect to the fact that the application is a real time application the ...
2
votes
2answers
200 views

Can I further optimize this solution for HackerRank's “Making Candies”?

My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
0
votes
1answer
84 views

Finding Mersenne primes

An attempt to find Mersenne primes using the Lucas-Lehmer primality test: ...
5
votes
2answers
549 views

Determine the roots of a Quadratic Equation

A code that determines the roots of a quadratic equation. Also, determine the following based on the discriminant b² – 4ac: If b² − 4ac is positive, display: “There are TWO REAL SOLUTIONS.” If b² − ...

1
2 3 4 5
12