Questions tagged [math]

Math involves the manipulation of numbers within a program. For general math questions, please ask on math.stackexchange.com. Note: If your question is about unexpected results in floating point calculations, please read https://stackoverflow.com/questions/588004/is-floating-point-math-broken first.

7,151 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
22votes
1answer
2kviews

The correct bone data to export from blender to view in ogl?

Edit (Original post below): So I have come up with the following code. I can export the mesh, bone structure and animations. I can animate a simple skeleton. But for some reason if I animate more ...
user avatar
11votes
0answers
421views

In Idris, why do interface parameters have to be type or data constructors?

To get some practice with Idris, I've been trying to represent various basic algebraic structures as interfaces. The way I thought of organizing things at first was to make the parameters of a given ...
user avatar
10votes
1answer
815views

Correctly compute the divergence of a vector field in Python

I am trying to compute the divergence of a vector field: Fx = np.cos(xx + 2*yy) Fy = np.sin(xx - 2*yy) F = np.array([Fx, Fy]) Analytic Solution This is how the divergence (div(F) = dF/dx + dF/dy ) ...
user avatar
  • 685
9votes
1answer
626views

Synchronize transform matrix of superview and individual views in different coordinate space

Given following view hierarchy: root (e.g. view of a view controller) |_superview: A view where we will draw a cross using core graphics |_container: Clips subview |_subview: A view where ...
user avatar
  • 30.9k
9votes
1answer
5kviews

How does one divide a big integer by another big integer?

I've been researching this the last few days and I have been unable to come up with an answer. I have come up with one algorithm that works if the divisor is only one word. But, if the divisor is ...
user avatar
  • 1,341
8votes
0answers
190views

How to get sympy to give solutions with smaller coefficients

Consider the following example Diophantine equation -118w + 989x + 918y -512z == 0 You can solve this in sympy with: import sympy from sympy.solvers.diophantine import diophantine w, x, y, z = ...
user avatar
  • 17.6k
8votes
0answers
146views

Testing which trits are set in a binary representation

I have a problem for which I have eight elements that can contain 0, 1, or 2. I can easily represent this in 16 bits, but for SIMD efficiency reasons, I need it to occupy 13 bits (it is not the only ...
user avatar
8votes
0answers
731views

Which axioms may be safely added to Coq?

This question is a request for references or explanation. The main idea is: What if I add every axiom from standard library of Coq? Will it raise a contradiction or they are well-adjusted to each ...
user avatar
  • 677
8votes
0answers
103views

Isabelle/HOL sequents: meaning of types o, seq', meaning of nonterminals seq, seqobj, seqcont

I am trying to understand https://www.cl.cam.ac.uk/research/hvg/Isabelle/dist/library/Sequents/Sequents/Sequents.html and https://www.cl.cam.ac.uk/research/hvg/Isabelle/dist/library/Sequents/Sequents/...
user avatar
  • 2,305
8votes
1answer
775views

Increasing accuracy of solution of transcendental equation

I have a specific kinematics as a part of a more complex machine and need to compute some physical parameters that are very hard (more like impossible) to measure with proper accuracy with instruments ...
user avatar
  • 44.6k
8votes
1answer
1kviews

Augmented Reality Bearing/Heading/Azimuth confusion. (iphone ARKit code)

- (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second { //first is origin //second is point float longitudinalDifference = second.longitude - first....
user avatar
  • 181
7votes
1answer
216views

Optimal covering with non-uniform discs

What kind of algorithm can I use to search for an optimal (minimum area) covering of a limited region of the XY plane with n discs ( xj, yj, rj ) ? I've found many investigations on fixed radius discs,...
user avatar
  • 108k
7votes
0answers
2kviews

Calculate SMA's Slope in pine script

I'm want to calculate the slope for the Simple Moving Average's (SMA). I have already tried the following code which is mathematically correct. rad2degree = 180/3.14159265359 //pi sma2sample = sma(...
user avatar
  • 333
7votes
0answers
254views

Implementing a custom datatype in Sympy

I want to perform calculations with a binary operation (Tensor) that takes two non-commutative arguments, converts them into something like a pair, and then does funny things when I multiply these ...
user avatar
7votes
1answer
416views

Point/Feature detection from upper and lower threshold of curvature - Curvilinear Quadrilateral Shape Detection algorithm

Is it possible to create a polygon from a set of points along a line with rough curvature, such that the points are selected between two values of curvature? I am attempting to retrieve an ...
user avatar
  • 3,281
7votes
2answers
3kviews

Line offset (parallel lines) without cusps

I'm trying to draw lines with offset to main line like on attachment. I have problems with my code. It generating intersections and cusps on the lines. (attachment) Maybe someone can help me with ...
user avatar
  • 1,045
7votes
1answer
1kviews

Parametric equation to place a leaflet marker on the circumference of a circle is not precise?

I am working on an application where I have the center of a circle and the radius and I am plotting the circle with the help of Leaflet. I placed a marker on the north most end of the circumference ...
user avatar
  • 12.1k
7votes
3answers
2kviews

AS3 - geometry - perspective projection of a point on a 2D plane

I'm currently struggling on a problem that seems far beyond my maths capacities (been a long time since I've made some proper maths...) and I would appreciate some help on that. Here's my setting : I ...
user avatar
  • 495
7votes
3answers
6kviews

Calculating a quad curve between two xy points

I have two (x,y) points start and end. I want to animate from start to end but instead of going a linear way I want to create a curved path. I am quite sure I'm not looking for an easing because I ...
user avatar
7votes
1answer
5kviews

Rounding away from zero in Javascript

We are building a table in Javascript with Handsontable representing currency amounts. We give the user the possibility of render the amounts with two decimal places or no decimal places (it's a ...
user avatar
  • 574
6votes
0answers
167views

Checking condition on matrix/array element-wise modulo an integer

My aim is to check whether a matrix (i.e. a 2D array) modulo d is Symplectic (see condition on wikipedia: https://en.wikipedia.org/wiki/Symplectic_matrix). That is, whether there is any Symplectic ...
user avatar
  • 93
6votes
0answers
118views

Why is the calculation result different between sassmeister and local environment?

I do complicated calculations. For example, the following mixin returns 0.00000096 for SassMeister (used in compiler dart-sass v1.18.0). But with gulp-dart-sass this gives different results (9....
user avatar
  • 764
6votes
0answers
298views

How to call a julia method defined in an imported package from c++?

I need a c++ library to compute the polygamma function for complex arguments. After some googling that brought me to this https://scicomp.stackexchange.com/questions/23194/i-am-searching-for-c-code-of-...
user avatar
6votes
2answers
611views

Find minimum number of triangles enclosing all points in the point cloud

Input You have a points list which represents a 2D point cloud. Output You have to generate a list of triangles (should be as less as possible triangles) so the following restrictions are ...
user avatar
6votes
1answer
474views

Matrix indexes with ejml (or other Java libraries)

I'm using ejml library for writing mathematical algorithms in java. I think it is pretty useful, but I need to know if there is a fast mode (like print()) to print a matrix with indexes. Example: ...
user avatar
  • 837
6votes
0answers
226views

Problems with including math parser "exprtk"

Instead of programming a math parser myself, I'm trying to implement the exprtk (exprtk) into my project. It works fine if I implement it in a console project. However, it fails in my CLR project. The ...
user avatar
6votes
3answers
252views

Feedback on ranking algorithm options for my website

I am currently working on writing an algorithm for my new site I plan to launch soon. The index page will display the "hottest" posts at the moment. Variables to consider are: Number of ...
user avatar
6votes
1answer
955views

Photoshop Photo filter math

Photoshop has a nice feature called Photofilter (Adjustments > Photo Filter). I've tried to understand the math behind it but no luck. It's not a standard blending and not a multiplication. By ...
user avatar
  • 601
6votes
1answer
2kviews

How to show math equations in QTextEdit?

Does anyone know how to show mathematical equations in QTextEdit written in any format (TXT, MathML, MML, LaTeX, HTML, XML or anything) using only Python, that is without using 3rd party packages like ...
user avatar
  • 1,365
6votes
3answers
201views

Three argument pow for arrays

pow accepts a third argument for modulo pow(x, y, z) that is more efficient computation than x ** y % z. How can you do that with arrays? What I've tried: >>> import numpy as np >>> ...
user avatar
5votes
2answers
78views

Find min(A[L], max(A[L+1], min(A[L+2],...,a[R]))) in range

Give array A consist of N (1 <= N <= 10^5) positive integer less than 10^6. Given Q (1 <= Q <= 10^5) queries, for each query of the form (L, R) (1 <= L <= R <= N), print out: min(...
user avatar
5votes
0answers
160views

C++ How std::fmod avoids round-off errors when calculating mod(a,b) for a which is much bigger than b

I have a small function to calculate mod as follows: double mod(double a, double b){ return a-floor(a/b)*b; } mod(1e15,3) returns 1 correctly, but mod(1e16,3) returns 0 due to numerical round-off ...
user avatar
  • 355
5votes
0answers
263views

Numpy Convolution implementation for mode = same

I hope I chose the right platform for this question (wonders if it’s more related to math exchange or computer science). In any regard, I’ve read about convolution in signal processing and I want to ...
user avatar
  • 2,012
5votes
1answer
367views

Prove that the powerset of a finite set is finite using Coq

While trying to prove some things, I encountered an innocent looking claim that I failed to prove in Coq. The claim is that for a given Finite Ensemble, the powerset is also finite. The statement is ...
user avatar
5votes
1answer
867views

How do you do large number math in QtQuick Qml using JavaScript

I want to calculate the circumstance of the Sun around the Galaxy; the Math Formula is ((241828072282107.5071453596951 * 666) * 2) * 3.14159265359, using QML JavaScript I get the answer ...
user avatar
  • 103
5votes
1answer
664views

Generate a random number within a range using a poisson distribution

I need a Poisson distribution. Currently I have the following code: public static int getPoisson(double lambda) { double l = Math.exp(-lambda); double p = 1.0; int k = 0; do { ...
user avatar
  • 75
5votes
0answers
617views

Intersection area of a 3D Triangle and AABB

I am looking to find the actual surface area of an intersection between a triangle and an AABB. Currently, I am using Tomas Akenine-Möller's AABB-Triangle intersection test, which works quite well - ...
user avatar
5votes
2answers
576views

Algorithm to assign Team based on player's choice

I found very similar questions in here but I couldn't find a solution which would work for me. So here's the problem: I have 4 teams and a vast (higher than 4) number of players. Each player ranks ...
user avatar
  • 73
5votes
0answers
701views

Python integration with poles

I'm trying to integrate an expression with poles, something like: where the poles are at z = ib-a, ib+a, -ib-a, -ib+a Python has a range of integration tools in scipy, but I don't know if there are ...
user avatar
5votes
2answers
464views

Objective-C division on 32/64-bit device produces different results

As described in the title, when I try to do the following divsion I get two different results depending on the architecture of the device: unsigned int a = 42033; unsigned int b = 360; unsigned int c ...
user avatar
  • 389
5votes
1answer
902views

2D Self-Deconvolution in MATLAB

I have some data, a 2D matrix we'll call A, which I know in theory can be described by a self-convolution of another matrix we'll call B: A=conv2(B,B) I am trying to extract B. Is there a way to ...
user avatar
  • 181
5votes
1answer
1kviews

Is there a good GLSL hash function?

So I am still getting upvotes for my ancient comment on this question: What's the origin of this GLSL rand() one-liner? And it got me thinking, what would a good GLSL hash function look like? ...
user avatar
  • 4,796
5votes
3answers
1kviews

jQuery returns not a number only when I use subtract

I am having an issue with jQuery that I can't seem to figure out. If I do console.log($(window).width()/2) I get a numerical value. If I do $('.modal_box').outerWidth() I get a numerical value. ...
user avatar
  • 1,753
5votes
1answer
130views

Optimization: minimize painting errors

You are given an m*n grid, where each cell is marked either "b" or "w". You are also given black and white paints. You are allowed to use k strokes, each of any color (black OR white), a stroke is ...
user avatar
5votes
2answers
837views

Libm optimised for ARM?

Is there a libm (libmath) that is optimised for ARM(v6) processors? I was looking at the GNU implementation and it doesn't seem to be optimised (but it does have x86 ones). It seems that most ...
user avatar
5votes
1answer
3kviews

Is there C++ class that implements operations with permutations?

Is there C++ template class that implements operations with permutations and permutation group? Such class has to implement finding product and inverse, multiplication, etc.
user avatar
5votes
1answer
554views

Line Intersection with rotated box collider object

I'm implementing my own Raycasting library to learn how it works. As a starting point I have a box that rotates and, using rays, detects the different obstacles that it encounters in its way. Worth ...
user avatar
4votes
0answers
121views

How do I solve these Nonlinear equations in Python?

I'm new to stackoverflow so hopefully this post follows all the rules and is in the correct place. If there's any problems let me know so I don't do it again! Also I hope a little LaTeX notation is ok ...
user avatar
4votes
0answers
347views

How to generate equidistributed points (evenly distributed) on the surface of a sphere, specifying the distance between neighbouring points

In a nutshell: I need an algorithm that can generate points on the surface of a sphere, and the euclidean distance between each point and its neighbors must be the same. Here is a quick explanation ...
user avatar
  • 1,452
4votes
1answer
457views

Algorithm with O(m (log n + log m)) time complexity for finding kth smallest element in n*m matrix with each row sorted?

I ran into an interview question recently. We have m*n matrix such that each row is in non-decreasing order (sorted with distinct elements). design an algorithm on order O(m (log m+ log n)) to find k-...
user avatar

15 30 50 per page
1
2 3 4 5
144