# Questions tagged [math]

17247 questions

1

83

Views

### Problem with calculating the bounding box of a 3D object with transformation

So I have a really weird behavior for my bounding boxes. Everytime I translate an object with any value being negative the bounding box gets stretched to the 0 point. Here is how it looks with a positive translation: Everything is fine. But now I translate it with a negative Z coordinate. Here is my...
RalleYTN

1

160

Views

### How to know IF a line segment intersects a triangle in 3d space?

I have a triangle defined by 3 points in 3d space. I also have a line segment defined by 2 points in 3d space. I want to know if they intersect. I don't really need to know the point of intersection. I don't know any calculus but I know some trig. I know some about matrices but I understand vectors...
Joe Cool

2

110

Views

### Mathematical solution to split X teams into 3 Teams per day

I am trying to split X number of Teams into 'play days' which consist of 3 teams per day There is more than one solution to solve this for 15 teams. What is the best approach to find all possible fixtures/match plans for team count 9-21? Team count of 11, 14, 17 and 20 also cause problems, because t...
Vid Man

2

46

Views

### Why some very close floating numbers cause such divergence in this Python code with 3.4.x to at least 3.6.6 version?

When I execute this code it's generate arithmetical divergence or not with very close float numbers it's occur when the numbers are to the form 2**n-p/q can produce a acceptable result and sometimes a very fast divergence. I have read some documentation about floating point arithmetic but I think th...
Rossignol_fr

1

41

Views

### Algorithm that can compute values of variables based on the result of specific sums of those

This might be a duplicate question, but I wasn't able to find this on stack overflow. Take some variables, which all represent a chance of something. That means that all variables have a value between zero and one (both inclusive). The values of these are unknown. However, I have some equations with...
RgSW

1

33

Views

### How to evaluate a derivative at a given point in Maxima

I need to generate in the Maxima software the expression f'(e) - 1, or using other notation, (df/dx)(e) - 1. I'm doing it calculating the derivative of f(x) and then making a substitution: subst(%e, x, diff(f(x), x)) - 1 However, I get the following result: Does any body know how could I get the cor...
Jaime_mc2

1

55

Views

### What is the best way to round a float in elixir

I am trying to round a Float in elixir to 2 decimal places. If I have the number 12.555, I would like my rounding function to return 12.56 I originally thought that the Float.round was what I wanted but this function does not always return the answer I would like. For example... iex()> Float.round(1...
RobStallion

29

254.8k

Views

### Why do inaccuracies occur in floating point math operations?

Consider the following code: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why do these inaccuracies happen?
Cato Johnston

2

2.3k

Views

### jQuery UI slider with scaled ruler as height selector

I'm trying to work out the math on this sort of tricky input for a height selector. Basically - I have a jQuery UI slider to select a height. It increments in inches and has a min of 0 and a max of 120 (10' tall). As the user moves the slider, a corresponding ruler graphic moves. I've set up a jsfi...
pstinnett

0

12

Views

### Does anyone know the name of this algorithm or have better idea in time trend

I found this algorithm for time trend Calculate if trend is up, down or stable But I cannot figure out what is this and why should do this. Or is there any suggestion or existing model for related problem?
Lun Tsai

1

16

Views

### Math.log wrong results for big numbers [duplicate]

This question already has an answer here: Inaccurate Logarithm in Python 8 answers math.log2 and math.log are giving me wrong results for some high numbers, tested it via online py interpreter and on a local machine. >>>print(2**72) >>>4722366482869645213696 #Correct >>>math.log2(4722366482869645...
Ragnar Lothbrok

6

69

Views

### Javascript - simple exercises

I have a task to write a function getEvenAverage, which should take only one argument - array. This function should return an average value of even numbers from this array. If in the array there aren't any even numbers the function should return null. I'd really appreciate any feedback :-) function...
P.Pon

1

172

Views

### Creating a list or sequence of numbers up to a certain value in F#

Suppose I want to create a list or sequence of all cubic numbers under 5555, or fibonnacci numbers under 4500 - How would I do this? I can generate a list or sequence of these , but I don't know how to make them terminate after a certain point. In the case of the fibonacci sequence it is difficult...
Dr. John A Zoidberg

1

414

Views

### Can't use variable in DateTime's modify() function. I'm getting an error: Object of class DateInterval could not be converted to string

I managed to dynamically load and compare several time values in PHP. Right now I am stuck here: \$additional_time = \$entry_start->diff(\$compare_from_timeformat); \$additional_time ->format('H:i'); \$avaliabletime->modify('+1 hours'); I want to replace the +1 with \$avaliabletime but if i try something...
Gramrock

1

1.4k

Views

### big Int addition in Golang

I am trying to add 100 numbers each of them has 50 digits. Trying to use math/big package to achieve it, but the result does not seem to be right. I am pretty sure I am doing something wrong. Playground example: package main import ( 'bytes' 'fmt' 'math/big' 'strings' ) func main() { a := strings.S...
Mikki

3

2k

Views

### Find angle of point on circle

Imagine I have drawn a circle with center coordinates (cx,cy) on the screen and a random point (A) is selected on the circle. By having the the coordinates of point A, I need to find the angle of (a). Update: I have tried using the following formula: Math.toDegrees(Math.asin(((x - cx) / radius).toDo...
Hamed Momeni

3

251

Views

### How to lowpass filter an angle value

I'm receiving angle updates from a sensor in radians and I want to pass them through a low pass filtering function to smooth them slightly because of noise. My low pass filter function looks like this protected void lowPass(float alpha, double[] input, double[] output) { for (int i = 0; i < input....
Magnus W

1

47

Views

### Why isn't this rounding up (Javascript)?

the value of the name is 115.5, but when I run the below code, I get 115. Why? I thought Math.round() rounded up at .5. Please help. Math.round(parseInt(document.getElementsByName('prod_Unit_Price_1')[0].value)));
DMill

2

62

Views

### Rotation accuracy error builds up too fast?

When applying rotations one after another, precision errors accumulate. But I am surprised of how fast the error builds up. In this example I am comparing 2 transformations that are equivalent in theory. In practice I get 0.02 degrees error by doing just 2 rotations instead of one. I was expecting t...
Octo

3

66

Views

### How to calculate percentage from a table on R

Hello, I have a table with 14 observations and 16 variables. (S0 to S11 and the sum of the row at the end) I would like to calculate the percentage of each value on the total (last column). I tried prop.table but it's not giving me the right percentages. I also tried apply but same pb. Here is...
TWCars

2

100

Views

### Get the min and max value in android studio

what I am trying to do, is get the minimun and maximun value from some float values I put manually. But I do not know how to do it. any helping coidng would be great. Thank you. Asume a list of floats p1, p2, p3, p4, p5, p6, p7, p8, p9
jvargas

2

63

Views

### Integer division rounding down in C# (for negatives)

Is there any way to perform integer dividing in C# (without float or decimal, I need to keep this one very fast) that rounds down the number? The default division just discards fraction argument. Consider: 1 / 2 = 0 // That is correct -1 / 2 = 0 // ... but I want to get (-1) here! My division will t...
PiotrK

1

32

Views

### How to use members of a structure for arithmetic operators (add,sub,mul,div a variable to a struct member)

Sorry for the noob question. How do i use arith operators to variables within the structure? I have this struct struct account { int no; char name[100]; int pin; float id; }; what I want to do is add a value to float id #include #include #include #include main() { struct account { int no; char...
marc jose

2

44

Views

### Is there a cleaner/simpler way for writing this formula in code?

I need to return a double value. This value is derived from this formula. monthly interest = balance * interest rate / 100.00 /12.0 Due to some precision issues, I am to use BigDecimal during calculation and return a double value (as this is how money is represented). I've tried the code below and i...
Connie Varley

8

4.4k

Views

### Finding the distance between two objects

For my game, I need to find the distance between two objects at certain times. My question is simply can the findDistance function be improved? I don't seem to have any issues, I'm only curious if it could have been done better. Also, if I were to do this in a 3D setting how would I go about calcula...

1

8

Views

### Error obtaining logarithms of base 2 in c

I want to obtain the binary logarithms of the numbers 1 to 2048, but I don´t know why it doesn´t work, it doesn´t obtain the right numbers. If I use floats, it works, but it used to work with integers, i have already done a program with this method and now it doesn´t work because of that. Chang...
IssacCloudVII

0

13

Views

### How to use keyboard and mouse input to navigate a figure

I'm working on a project involving viewing a 3D from different viewpoints using mouse and keyboard input. When I submitted my first draft, I received the following feedback: 'Your object did not react to any of the buttons I pressed to change the camera view! The object of this project is to have th...
Tracy Harrison

3

142

Views

### Find a tangent between line segment and circle

I have a line segment A (x1, y1), B (x2, y2) and a circle with the center C (x3, y3). Also I have radius of the circle. How do I get tangents? These tangent lines should always be parallel to line segment. P.S. Sorry if it is doesn't make sense to you, I am very very bad at math. Ask me any questi...
boshetoonmai

19

121.6k

Views

### Check if a number is a perfect square

How could I check if a number is a perfect square? Speed is of no concern, for now, just working.

0

232

Views

### Random Points in an n-Dimensional Hypersphere

This Matlab code, creates a set of random points defined by Cartesian coordinates and uniformly distributed over the interior of an n-dimensional hypersphere of radius r with center at the origin. the source is here. clear all clc m = 20000; n = 2; r = 2; %// generate circle boundary C = [3 4]; %...
Shdotcom

0

41

Views

### Is there an established name for this type of Operation and do efficient algorithms exist for it?

The original dataset constists of X,Y datapoints where each datapoint satisfies the condition that no other datapoint has both X and Y values lesser than its own. The operation performed is to add a new datapoint to the dataset, and then remove any datapoints which no longer satisfy the condition ab...
Caustix

0

51

Views

### Adding two numbers,by two decimal precision

My PHP Application is getting to the PDO query numbers like this: Number A is 95199.60 from \$_POST['num_a'] Number B is 21895.91 from \$_POST['num_b'] The result should be 117095.51 but in the database it occurs 117095.5 However, in the same query Number A in the database is 95199.6 and number B is 2...
Marcin

0

276

Views

### How to get pitch correctly with GLM?

I am trying to limit rotation of the camera around X axis by 90 degrees. My camera uses glm::quaternion to store orientation in space. For changing camera pitch angle I use the code: m_orientation *= glm::quat(vector3(glm::radians(angle), 0.0, 0.0)); And later I extract pitch angle I use: float pitc...
Nikolai Paukov

2

223

Views

### How to get diagonal and antidiagonal number

If you can get the row and col from a 1-dimensional array, given the width and formulas below. how would you get the diagonals and anti-diagonals? my example is trivial. Looking for something that scales to MxN, and is general. pseudo code A = array[26]; width = 5; row(index) = floor((index / wid...

0

36

Views

### Elastic line equation in Matlab - Error using Mupadengine/feval - Error in dsolve>mupadDsolve - Error in dsolve

I can't understand the solution of multiple differential equations in Matlab. In this example, I'm trying to work with independent equations: the program should solve them separately (and it does, see below) and together (it doesn't!), shouldn't it? N.B. The equations describe the elastic line accor...

2

57

Views

### sympy dsolve returns incorrect answer

I'm using sympy.dsolve to solve a simple ODE for a decay chain. The answer I get for different decay rates (e.g. lambda_1 > lambda_2) is wrong. After substituting C1=0, I get a simple exponential -N_0*lambda_1*exp(-lambda_1*t)/(lambda_1 - lambda_2) instead of the correct answer which has: (exp(-la...
Daria

3

70

Views

### Pseudorandom Number Generator with slight bias

I've thought about this for a while to no avail... How would one go about creating a pseudorandom number generator with a slight (we're talking only apparent after millions, maybe billions, of iterations/tests) bias towards a single number. So, for example, if our generator is producing numbers from...
T. Fo

0

57

Views

### Is it possible to search through a very large excel file that includes latitude and longitudes and return rows within a certain radius? (Java)

I have a very large excel sheet (about 30,000+) records of house prices and their location (a latitude and longitude value). At the moment I can parse parts of the excel sheet into the console of Eclipse using Apache POI. However is it possible to return only certain rows and their house prices if t...

1

29

Views

### Optimally calculating multiple database items into a configuration

Good morning! I'm working on a couple of optimization things here...I can't find the 'best' answer to this, so I thought I'd ask you geniuses. Thanks in advance for your thoughts! Always appreciate this community :) We have a database, it has about 150 items in it, maybe more (haven’t finished...
John

1

63

Views

### Trouble understanding the meaning of w1=w|w|

Alright so I have a language L={w:|w|≥1,and w1=w|w|}. w1=w|w| are w subscript 1 and w subscript |w|. Im confused with what w1=w|w| means. |w| means the length of w, but if we're setting w1 as in the first word to the |w|th word in the language, then what is that exactly? When we say |w| here the...
Alvin Roach