Questions tagged [programming]

For mathematical questions related to programming, and questions where a computer-aided solution is strongly suggested. A strong connection with a mathematical topic is needed to make programming questions on-topic.

This should not be the only tag. Consider also using the tags (algorithms), (numerical-methods), or (linear-programming).

717 questions
0
votes
0 answers

calculating dynamic offset

there are two given functions. One (blue) is detailed but has a certain offset from its actual value. The other (red) doesn't have this offset, but it is less detailed. I'd like to use the first function for further calculations, but without the…
Era D
  • 1
0
votes
1 answer

Why are such two methods functionally equivalent from a mathematical perspective?

To program a function that tests whether all elements in an array are greater than 5, the straightforward way will be: bool test(std::vector arr){ int number = 0; for(auto i:arr){ // Iterate over all elements if(i>5){ …
xmh0511
  • 205
0
votes
1 answer

Why is this string reduction solution correct?

I was trying to understand one of the solutions for the following string reduction problem (from hackerrank). Given a string consisting of the letters a, b and c, we can perform the following operation: Take any two adjacent distinct characters and…
gkv
  • 109
0
votes
0 answers

Getting a smooth function between 0 and 1 with maximum increase around av

I'm working on a method to predict certain things to change, for this i need to create a function with the following parameters: av: Average; >= 0 max: Maximum value; < av; can be much larger than av v - Value; > 0; < max The function needs to end…
Felix K.
  • 101
0
votes
0 answers

What's a good way to 0 denominator for ratio calculation?

I'm writing a program that needs to compute the ratio of the difference between two numbers over the second number. i.e., (B-A)/A I'm trying to figure out what's the best way to handle the case of 0 denominator. Practically, I could have a special…
Josh
  • 11
0
votes
1 answer

Linear programming formulation question

This problem is driving me mad, it's supposed to be really simple but I hate word problems such as this. I have the answer and can formulate other problems fine but for the life of me can't figure this out. I don't understand where the numbers in…
0
votes
0 answers

Algebraic question to find X

please accept my apology if this is the wrong place or style as to ask a question like this. I usually post in StackOverFlow, so I don't know if there's any specific maths rules... While I deal with algebra all day with programming, maths isn't…
vr_driver
  • 109
0
votes
0 answers

Improving Excel's solver speed for differential equations

I have an Excel spreadsheet that contains a linear differential 5 DOF vehicle dynamics model. I use the built-in solver in a loop to numerically solve the equations. I used it qualitatively for a while, but then in the search for increased accuracy…
0
votes
0 answers

How can I approach this set problem?

Here is my problem : Let's say we have a two dimensionnal array of $n \times n$ squares. In this array there are m targets and the player knows this value. Each turn you can shoot a square, if there is a target the target disappears and you get…
0
votes
1 answer

Programming a not-so-powerful calculator

I have three numbers P, Q, R subject to the following conditions:- (1) P, Q, R can be all different; or (2) P, Q, R cannot be all equal at the same time; or (3) Two of them are equal. That is, (P, q, r) or (p, Q, r) or (p, q, R) where small letters…
Mick
  • 17,141
0
votes
1 answer

Calculate divisions depth

Imagine having a line segment A of size S (ex. 64 units). To calculate this segment depth D it's divided incrementally by 2. No division means depth is 0, divided once means depth is 1 (2x32), dividing the divided again by 2 - D = 2 (4x16), and so…
Janis Taranda
  • 127
  • 1
  • 6
0
votes
1 answer

Formalisation of distance algorithm

I am trying to formalise a small algorithm and I have difficulties writing it in mathematical terms properly. I have a vector $d$ with $d = 1, \dots, N$ and a vector $c$ with $c = 1, \dots, C$. What my algorithm is doing is to compute a distance…
giac
  • 103
0
votes
1 answer

Simplifying conditions correctly mathematically

All in all, i wanted to know if if it's possible to mathematically simplify 'if expressions' in code, by replacing every condition by a set. Here's an example : I have two 'if expressions', let's call them S1 & S2 respectively : S1: ((x > 0) || ((x…
Lorenzo
  • 105
0
votes
0 answers

How can I find the max. sum of 'k' subarrays?

I am preparing for a national programming competition and I encountered this problem. It is as follows : - You are given an array of length M. You are required to select K non-intersecting subarrays. The cost will be considered as the sum of all…
0
votes
1 answer

Latex code required for drawing geodesic space

I want to draw that particular picture in $\LaTeX$ but does not getting the point how to make code in latex kindly give some suggestion: