All Questions
Tagged with numerical-methods algorithm
151 questions
2
votes
2
answers
138
views
Algorithm for calculating fraction from decimal with limits
The algorithm for calculating a fraction from a decimal number is known and there are enough examples for that. In my case I need to find a fraction for a given decimal where A = N/D is optimized but ...
2
votes
0
answers
56
views
Locating a real-valued function in a 2-dimensional matrix [closed]
I need help solving the problem of locating a chosen function in a 2-dimensional matrix. Let me explain what I mean precisely. I have two 1-dimensional real grids (arrays) of x(i) and y(j), where i, j ...
2
votes
2
answers
101
views
Creating a short, d-dense list of points on the sphere S^4 in Python
I am a mathematician and this is my first time using Stack Overflow, sorry if the question is not adequate or there is some better place to ask this. I would like to know if there is a standard way ...
2
votes
0
answers
98
views
C++ Hermite interpolation - Generate coefficients & value
I'm trying to fix my Hermite interpolation program, which is supposed to output the coefficients and value at a point, but it seems the results are wrong. It currently looks like this:
#include <...
0
votes
1
answer
167
views
Numerical vs. algorithmic methods
In the book I am currently reading, there is a distinction made between deterministic numerical methods (e.g. gradient-based: Newton's method, gradient-free: Nelder-Mead) and algorithmic methods (e.g. ...
3
votes
2
answers
240
views
An Algorithm for solving linear inequalities with two variables
I am trying to find an algorithm to determine existence of strictly positive integral solutions for a set of linear inequalities with two variables and the following form:
𝑎1𝑥 + 𝑏1𝑦 ≤ 𝑙1
𝑎2𝑥 + ...
2
votes
1
answer
327
views
Finite difference method for solving the Klein-Gordon equation in Matlab
I am trying to numerically solve the Klein-Gordon equation that can be found here. To make sure I solved it correctly, I am comparing it with an analytical solution that can be found on the same link. ...
1
vote
3
answers
839
views
How to distinguish odd and even for big numbers more efficiently?
Please let me know by comments if there are already some similar questions.
When we usually try to distinguish odd and even numbers we can try the following code,
in C++.
int main() {
int ...
0
votes
0
answers
403
views
How the mod() function works internally in languages like Java, Python, etc?
in Java or Python this function is given by the % operator.
I would like to know the mathematical algorithm that uses this function.
0
votes
1
answer
366
views
Arranging diagonal matrix in ascending order
I have a diagonal matrix and a matrix of same dimensions. How do I arrange the diagonal matrix in ascending order and then do the same steps on the other matrix ? For example if my matrix is 3 x 3, ...
0
votes
1
answer
358
views
Gauss-Legendre and Gauss-Chebyshev quadrature in FORTRAN
Please I wrote a code for 5D integration using Gauss-Legendre and Gauss-Chebyshev in FORTRAN but when I compile it is very slow. Please can someone tell me how to increase the speed?
MODULE GauLegMod
...
1
vote
0
answers
785
views
Newton Polynomial from Divided Differences Table in C++
Background
I'm attempting to create a program that creates a fully simplified Newton polynomial from a divided differences table. I already have all of the resources to do this, but I'm confused on ...
0
votes
1
answer
175
views
Haskell: Is there a way to use list comprehensions to make a tridiagonal matrix or make mine more efficient?
My goal is to make a tridiagonal matrix in an efficient way using either list comprehensions or a more efficient algorithm but I am fairly new to Haskell. I am attempting to solve boundary value ...
0
votes
1
answer
306
views
Adaptive trapezoidal rule and clarifications on priority queue implementation
On the subject of adaptive trapezoidal subdivision (see this and this), I need to solve a problem where evaluating f(x) takes a lot of time, so I need to do it the least number of times possible.
...
0
votes
1
answer
290
views
Minimize number of shops while reaching all customers
In this particular issue, I have an imaginary city divided into squares - basically a MxN grid of squares covering the city. M and N can be relatively big, so I have cases with more than 40,000 square ...
1
vote
0
answers
416
views
Efficient algorithm to find number density of points in 3D space
I have the position data for particles in 3D space. The particles are in random positions in the 3D box and I am trying to find the position of the maximum number density. Is there a simple algorithm ...
0
votes
1
answer
455
views
How to understand this efficient implementation of PageRank calculation
For reference, I'm using this page. I understand the original pagerank equation
but I'm failing to understand why the sparse-matrix implementation is correct. Below is their code reproduced:
def ...
2
votes
2
answers
151
views
Optimizing algorithm calculating (sin(x)-x)*x^{-3} (in matlab)
My task is to write optimal program that calculates matrix Y, given matrix X, where:
y = (sin(x)-x) x-3
Here's the code I have written so far:
n = size(X, 1);
m = size(X, 2);
Y = zeros(n, m);
d = n*...
4
votes
2
answers
781
views
Tolerance criteria Brent's method
Stop criteria for Brent's method is
if abs(m) <= tol or fb == 0.0 then // root found (interval is small enough)
found := true;
However, what if abs(m) reaches below said tolerance but ...
4
votes
2
answers
354
views
Numerically calculate combinations of factorials and polynomials
I am trying to write a short C++ routine to calculate the following function F(i,j,z) for given integers j > i (typically they lie between 0 and 100) and complex number z (bounded by |z| < 100), ...
1
vote
1
answer
358
views
3d polyline offset along normal directions
Suppose a 3d polyline (i.e. polygonal chain of 3d point segments) is given with normals specified for each points.
Are there any algorithms to compute an offset polyline whose points lie at ...
1
vote
1
answer
87
views
Efficient Product of 3 Sparse Matrices that creates a dense intermediate
I have 3 matrices that are all sparse, A, B, and C.
I need to take the matrix product of AB, which results in a dense matrix.
After that, I need the element wise product of AB (element wise *) C.
C ...
0
votes
2
answers
574
views
Obtaining the functional form of a curve
The following is the plot of a curve f(r), where r is the radial coordinate, and plotted for different values of a parameter as shown:
However, I don't know the functional form of the curve and I am ...
0
votes
1
answer
824
views
Adaptive Simpsons Quadrature Algorithm for Double Integrals?
I'm currently using Numerical Analysis 10th edition by Richard L Burden as a reference for approximate Integration techniques. In there it describes the Adaptive Simpsons Quadrature rule that inputs ...
2
votes
1
answer
2k
views
Finding Fourier coefficients algorithm
Ok, so I have been trying to code a "naive" method to calculate the coefficients for a standard Fourier Series in complex form. I am getting very close, I think, but there are some odd behaviors. This ...
2
votes
1
answer
96
views
How to use positional arguments appropriately for a complex problem
I am revisiting a school project, which I did not complete to my satisfaction. Namely, I wrote an algorithm that takes an ALMOST arbitrary size set of equations and solves them iteratively. The ...
2
votes
1
answer
355
views
Performance of n-section root finding algorithm
I wrote a n-section algorithm for finding roots of a function. The working principle is exactly the same as is bisection method, only the range is divided into N equal parts instead. This is my C code:...
2
votes
1
answer
848
views
Fastest algorithm for computing 3-D curl
I'm trying to write a section of code that computes the curl of a vector field numerically to second order with periodic boundary conditions. However, the algorithm I made is very slow and I'm ...
0
votes
0
answers
213
views
Approximation (fitting) method for an unknown function
I'm trying to approximate unknown function, given x and f(x) values. The function itself represents computational complexity of an algortihm, so it can be polynomial, logarithmic, exponential etc. I'm ...
0
votes
0
answers
179
views
How to find the line which describes best a group of points?
So I've had this problem (not homework, don't worry) where I had to find the line that describes best a set of points if that makes any sense. I've come up with an algorithm which:
Calculates the ...
0
votes
1
answer
187
views
Finite Difference Method for Solving ODEs Algorithm
I'm trying to devise an algorithm for the finite difference method, but I'm a bit confused. The ODE in question is y''-5y'+10y = 10x, with y(0)=0 and y(1)=100. So I need a way to somehow obtain the ...
0
votes
1
answer
98
views
What is the formal error of token bucket and can it be calibrated?
I'm looking for a way to throttle the rate of a specific event. I have a hard limit on the number of events per second, but can tolerate some amount of error. The implementation needs to use as little ...
14
votes
2
answers
2k
views
Solving PDE with implicit euler in python - incorrect output
I will try and explain exactly what's going on and my issue.
This is a bit mathy and SO doesn't support latex, so sadly I had to resort to images. I hope that's okay.
I don't know why it's inverted, ...
4
votes
2
answers
64
views
Quickly compute `dot(a(n:end), b(1:end-n))`
Suppose we have two, one dimensional arrays of values a and b which both have length N. I want to create a new array c such that c(n)=dot(a(n:N), b(1:N-n+1)) I can of course do this using a simple ...
3
votes
1
answer
606
views
c# - solving complexed ODE set
Introduction
Some sets od ODE can't be solved analytically. In this case there are plenty of well-know methods, especially in typical scientific software like MATLAB. As long as you stay with it, all ...
1
vote
1
answer
259
views
Improving Convergence Algorithms with Numerical Iterator in R
I am performing iterative computations to examine how y varies over x in R. My goal is to estimate the x-intercept. Now each iteration is computationally expensive so the fewer iterations needed to ...
0
votes
1
answer
54
views
Vector multiplication algorithm
Let A,B be matrixes of R^n space and b belong to R^n.Describe a fast algorithm to compute A^-2*B*A^-3*b.How many computations will the algorithm make?
This is an exam question I have for numerical ...
-1
votes
1
answer
2k
views
Algorithms to find min/max of a single variable function in fixed domain
I was looking for a numerical algorithm to find global minimum or maximum of a function in "given interval [a, b]", for example finding minimum and maximum of function
f(x) = sin(x)
in domain [3*...
-1
votes
1
answer
2k
views
How are 2nd order ODEs solved in python? With two variables in each of two second order differentials?
I have been given two second order ODEs and I've been asked to solve them with odeint in python.
These are the equations:
d^x(t)/dt^2 = 10dy(t)/dt + x(t) - (k + 1)(x(t))/z^3
d^2y(t)/dt^2 = - 10dy(t)...
2
votes
0
answers
90
views
Resources for fast fixed point algorithms
Looking for essentially what is posted in this much older thread
https://dsp.stackexchange.com/questions/20444/books-resources-for-implementing-various-mathematical-functions-in-fixed-point-a
It ...
0
votes
0
answers
31
views
An improvement of a conjugated gradient-like approach?
hello everyone the problem is slightly complicated to describe in details but i will provide as much details as i can, just ask if you need more information.
In the project i am involved in, i had to ...
2
votes
1
answer
334
views
How are sparse Ax = b systems solved in practice?
Let A be an n x n sparse matrix, represented by a sequence of m tuples of the form (i,j,a) --- with indices i,j (between 0 and n-1) and a being a value a in the underlying field F.
What algorithms ...
1
vote
1
answer
97
views
Imprecision in Approximating Pi using Monte Carlo Method
Area of the circle = Pi * R^2 and the Area of the square = 4 * R^2.
If we divide the area of the circle by the area of the square we get Pi / 4.
Let's have a square and an inscribed ...
0
votes
1
answer
456
views
Numerical methods to solve function with restricted domain
Methods to solve(root finding) the function with the restricted domain.
Suppose to solve the function
$sin^{-1}(\sqrt{E_n/V}) +a*\sqrt{2mE_n/h^2}=n*\pi$
where
$E_n,V,a,m,h n$ were all positive.
...
1
vote
2
answers
769
views
Matlab Euler Explicit ode solver with adaptable step, is there a way to make code faster?
I am trying to find a way to make this code faster.
Nagumo1 is the function that calculates the value of the two derivatives at time t.
function x = nagumo(t, y, f)
Iapp = f(t);
e = 0.1;
F = 2/(1+...
3
votes
0
answers
367
views
Gradient Descent code used to minimize a convex function not finding minima
I am trying to find the geometric median for a set of of n points. For this I have to minimize the sum of sqrt((x-xn)^2+(y-yn)^2).
To do this I decided to try a method of Gradient Descents. The ...
0
votes
1
answer
83
views
How to use the RK4 algorithm to solve an ODE?
I am using an RK4 algorithm:
function R=RK4_h(f,a,b,ya,h)
% Input
% - f field of the edo y'=f(t,y). A string of characters 'f'
% - a and b initial and final time
% - ya initial value y0
% - ...
2
votes
2
answers
461
views
Implementing Adaptive function plotting
I'm attempting to implement the Adaptive function plotting algorithm using the psuedocode from these two examples (both examples the same really)
https://www.andr.mu/logs/acquiring-samples-to-plot-a-...
1
vote
1
answer
319
views
Approximating an unknown value in Python
I need to approximate an unknown value, a bound that separates divergent values from those that converge.
I'm trying to do so like this:
# dont worry about the value of i, its one of many bounds ...