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.

math
Filter by
Sorted by
Tagged with
0 votes
1 answer
469 views

Grafana derivative not showing right output values

I put data values of a sinewave into elasticsearch and plotted it with grafana and set the derivative of the curve in the plot under it. I was expecting to see a cos wave with the same amplitude, ...
0 votes
2 answers
308 views

How to calculate how many bit sequences of size n with k bits set and c changes of bit values exist?

We know that calculating the number of n-length bit sequences with k bits set is equal to C(n,k)=n!/(k!(n-k)!)*. But I've recently asked myself how can you think about this problem once another ...
2 votes
1 answer
1k views

How to create incrementing base 62 alphanumeric sequence in SQL Server

I would like to create an incrementing alphanumeric sequence for a SQL server table, that uses numbers 0-9, lowercase letters a-z, and uppercase letters A-Z. So the series would be like 0, 1, 2, 3...9,...
0 votes
0 answers
77 views

Extracting a number from a 3d array that is the only one in the row or in the column c / c++

What i'm trying to do is a non-recorsive sudoku solver, I have an array sudoku[9][9] that is the sudoku itself with 0 as empty spaces and an array of arrays solutions[9][9][9] where all the possible ...
1 vote
0 answers
93 views

Multilateration of Sound in 3D Space

TL:DR - How can you find the 3D coordinates of a emitter than transmits an impulse signal? STORY: I'm working on something to improve my bird-watching. I've got a camera that can take pictures of ...
0 votes
2 answers
172 views

Add two decimal values [closed]

so I want to add two values (money values) but can't quite work it out. I keep getting a notice, I've tried number_format to format it but even using that I get the 'Notice: A non well formed numeric ...
1 vote
1 answer
522 views

R (and python) rounding up starting at 5 or 6 [duplicate]

I saw already a question with very large number of decimal digits R rounding explanation. round(62.495, digits=2) gives me 62.49. I would expect already 62.5, but it seems, R (3.4.3, 3.5.0) rounds ...
1 vote
1 answer
154 views

Multiplying fixed size fractions without using a larger container

I am given three unsigned numbers of size 128 bits: a, b, and c where a and b <= c I want to be able to calculate (a * b) / c with the highest possible precision. If a, b, and c were 64 bit ...
2 votes
2 answers
274 views

Handle summation of big binomials in Python

I need to compute this formula: It is an approximation of this integral but it doesn't matter, actually I just want to compute the value of Figure 1 with PYTHON, that's what the topic concerns. K, ...
1 vote
0 answers
53 views

Python math.floor calculation error [duplicate]

i have a problem when calculating floating point in python, here is an example: import numpy print numpy.floor(3*1.4+2*1.4) >> 6.0 it return 6.0 while i am excepting 7.0 i can fix this simply ...
0 votes
2 answers
293 views

python: interpolation: finding a rectangle that minimally include a point

I am implementing a bilinear interpolation as in How to perform bilinear interpolation in Python I have a sorted list of points that are the vertexes of my regular grid. [[x1,y1,z1],[x2,y2,z2],[x3,...
0 votes
2 answers
561 views

How to get change in Yaw Angle / Put Global eulerAngles into Local space

I am making an aircraft game and I need to the get the change in Yaw of the aircraft. I am attempting to save the previous frame's transform.eulerAngles and push them back to local space of the ...
0 votes
1 answer
389 views

Pie chart slice - center of mass

Using Highcharts, I'm trying to position rectangular elements above the "center-of-mass" of a pie chart slice. I have the formula/algorithm for finding the center of the slice: shapeArgs = Chart....
-1 votes
6 answers
1k views

how to use base2 in math

I have a list of base2 values (5 digits each) : [10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111] Is there a way to do math with them ...
0 votes
1 answer
2k views

How to get yaw degrees from transform in Unity?

I am making an aircraft game and I need to the get the Yaw of the aircraft. Below is working code to set pitch and roll but I can't quite figure out the yaw. private void _CalculateRollAndPitchAngles(...
0 votes
1 answer
44 views

Code not returning permutations

I have written python code to permute a list of numbers. class Solution: def __init__(self): self.permutations = [] def permute_helper(self, nums, chosen): if nums == []: ...
0 votes
1 answer
93 views

My Quadratic equation code terminates when I enter a non integer value, how can I get it to loop properly?

So I'm trying to get my Quadratic equation solution code to loop unless "0" is entered as any 1 of the quadratic coefficients. It works fine up until entering a non integer value, in which the ...
1 vote
1 answer
316 views

Faster way to calculate modulo when you have a previous answer?

I have a large number of modulo calculations to perform. The basic calculation is as follows: const uint64_t start; // Some "large" number that does NOT change uint32_t prime[bigNumber]; // ...
0 votes
2 answers
1k views

Scale down a dimension (set max width and height)

I'm writing a script to process a bunch of high-res images. Dimensions of these images vary from 1000 to 5000 pixels. To make them ready for web (upload) I need to scale them down. I'm not interested ...
-1 votes
2 answers
576 views

Translate code from 5 digit to 3 char

I have a code composed of five decimal, I need to store (compress) it in a field that can only contain 3 alpha numeric ascii printable characters . Is it possibile to have a bidirectional conversion ...
0 votes
0 answers
589 views

The result is overflow and underflow of exp function in C

I'm learning C language, I read about exp function at: https://linux.cn/man3/exp.3.html At RETURN VALUE, There are 2 cases: If the result underflows, a range error occurs, and zero is returned. If ...
1 vote
1 answer
75 views

How to make x += (1 - x) correctly works based on delta time?

Let's say that Time.deltatime can be used to get the real time between the code's update. So, if I have a sum and I want to make it works based on real-time I would make this: x += 1; Into this: x ...
1 vote
1 answer
225 views

Implementing the PRNG xoshiro256+ in Swift for a RN in a given range?

Based on the source written in c: here. I'm trying to implement the xoshiro256+ pseudo random number generator (PRNG) in Swift. I need to get to a point where the algorithm gives me a number ...
-3 votes
1 answer
381 views

linear programming algorithm for maximum proceeds

You can find the problem here First, I would assign a variable (x or y) to each quantity that is being solved for, and likewise write an equation for the quantity that is being maximized or minimized ...
1 vote
1 answer
584 views

finding peak intervals from column data

I have some integers values like this: 2 4 6 4 2 4 8 4 2 3 7 4 2 I need to find the peaks - which are the points of my array where the values stop increasing. In above example, there are three peaks ...
1 vote
1 answer
1k views

C#: How do I convert a 3D X Y and Z position to a 2D X and Y position?

What I would like is some kind of function to convert a 3D position, to a 2D position, e.g. Private Function Get2DPoint(ByRef x As Short, ByRef y As Short, ByRef z As Short) Dim newX = x + z '&...
0 votes
1 answer
48 views

Map country coordinates to screen pixels on hold

I have the coordinates of three cities in Latvia 57.4093885,21.5246563 56.9713962,23.9890814 55.8958226,26.4671762 I need to place them on my map of Latvia. I can not understand the algorithm as ...
0 votes
1 answer
3k views

Converting RGB value into ColorMatrix

I would like to colorize a black-white image. To do that, I use a ColorMatrix. For example, when I want to color the image red, I use this ColorMatrix: 1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 1,...
2 votes
0 answers
629 views

What algorithms exist for generating a texture atlas from a mesh?

I have a triangle mesh along with a function which defines the material properties at each point in 3d space. Using a given resolution in object space, I generate a triangular texture for each ...
0 votes
1 answer
120 views

How to make function 'extensible' in C?

I have the following function, which should work fine with a for loop to analyze whether or not the series of double results have "stabilized". What I have written analyzes 3 points total and I'm ...
0 votes
1 answer
221 views

karatsuba multiplcation of large numbers fails in javascript

I've tried two versions of a karatsuba multiplcation algorithm and they both fail with different results when I test them with large X and Y values. The parameters I'm using const x = ...
1 vote
2 answers
872 views

Circumference of Sierpinski triangle

I'm currently doing the this problem for own practice. I manage to pass all the testcases, so I can't figure out whats wrong. My code is: #include <iomanip> #include <iostream> #include &...
1 vote
1 answer
421 views

how to simply use eval string formula with Abs() in js (google app script)

I see there is eval() to calculate string formula. when i do eval("546+613-(30644-30600)-(789+834-(30665-30600))"), it works but it failed for eval("546+613-ABS(30644-30600)-(789+834-ABS(30665-30600)...
0 votes
1 answer
1k views

Calculating image rotation by 2 points

I have the following image: I would like to rotate the image in such a way that the 2 points are on the same line. The lowest points of the eyes should be on the same "level". How could I determine ...
1 vote
0 answers
429 views

Convolution filter 2D

I'm trying to create in C++ a convolution filter for an image. I'm using OpenCV library to manipulate my image. But my filter doesn't work properly. First attempt: #include <opencv2/opencv.hpp&...
0 votes
1 answer
250 views

2d circle rect collision and reflection doesnt work

I have game with map built by rectangles, darker rectangles (named "closed") mean its place where balls should be able to move, ball should reflect from the lighter rectangles(named "open") border. In ...
5 votes
1 answer
868 views

find if polynomial has multiple roots

I know a root of a polynomial is called a multiple root if it is also the root of its derivative I'm fairly new to prolog and I want to write a code where I have a list (for example: [3,2,1] for 3x^2 ...
-1 votes
2 answers
297 views

Converting an equation to JavaScript

I am trying to convert this math equation into JS: F(x) = 1/(x*sigma*sqrt(2*pi)*e^-(ln(x) -µ)²/(2*sigma²) I think I am messing up with some of my JS: var fx = 1/(x*0.24*Math.sqrt(2*Math.PI)*Math....
2 votes
1 answer
5k views

Numpy decimal points precision of complex numbers

Consider the following Python code which does some simple arithmetic operations over complex numbers in Python: import numpy as np s = 2 l = 5 v = np.array([np.exp(1j*2*np.pi/l)]) A = pow(s*v, l) + ...
0 votes
0 answers
284 views

Calculating Exponents in AT&T Assembly

How would I go about doing exponents in AT&T assembly, such as x ^ y with x = 3, and y = 10? Say that r14 has value 3. r15 has value 10. Where r14 = x, and r15 = y. Could I do this to calculate ...
-1 votes
1 answer
259 views

Double Pendulum returning nan results. Why?

When I run this code the double pendulum shows for a split second and then disappears. It seems most of the variables in the formula, num1, num2, etc., start returning nan after that split second when ...
0 votes
2 answers
1k views

How to detect outliers in an array of doubles?

I'm trying to determine whether or not there is data outliers in a list of doubles. Basically if anything is below 10 percent of the limits or above 90 percent. I have the following code working, ...
0 votes
2 answers
673 views

Find closest solution from a given vector for a linear equation in Matlab

Let's imagine that on one hand I have an equation like y = 5x + 3 and on the other hand I have two vectors of the same size - one representing x-values, other representing y-values (just random ...
0 votes
1 answer
1k views

How do I calculate the distance between an object of known size and my camera using VBScript?

I know the dimensions of the object and everything about the camera. The distance result needs to be updated at least 4 times per second. The camera feed comes from a robot with a wLAN connection to ...
-1 votes
1 answer
608 views

projecting a 3D helix on to XY plane

How can I project a 3D helix (XYZ cartesian coordinates) onto the XY plane. Basically I want to project different 3D helices from XYZ to XY plane.
2 votes
0 answers
44 views

How to convert data in hexadecimal to IEEE 754 format float value in swift [duplicate]

The input is [0x41,0xa7,0x33,0x33] -> is a UInt8 array. When I tried using the algorithm for IEEE 754 by splitting into sign, exponential and mantissa, I stuck in the middle due to the power function ...
-2 votes
1 answer
78 views

Random point within 3D mathematical volume

Quick question, if I've a formula for a mathematical 3D volume, is it possible to calculate a random cartesian coordinate (XYZ) point within the volume? And if possible, could the one to answer ...
4 votes
1 answer
374 views

Tensorflow L2 loss definition

I was wondering why tf.nn.l2_loss was set to compute half the L2 norm. Is there any special meaning to divide the L2 norm by 2?
1 vote
1 answer
6k views

Converting Analog Reading of Soil moisture to Percentage

I'm working on a project wherein my Arduino Uno reads the soil moisture, then sends the data to my Raspberry Pi 3. I'm using an HL-69 soil moisture detector, which gives off an analog output. The ...
3 votes
1 answer
81 views

rewrite animation to be time based (not flat speed based) [duplicate]

For some time now i am using animation for bullets, animation makes bullets go in sinusoidal trajectory from start point to end point. The only problem with animation i am having is that it is using ...

1
369 370
371
372 373
886