# 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).

590 questions
Filter by
Sorted by
Tagged with
29 views

### code a program in matlab (or python) that: [closed]

generate 10 random values ​​from 0 to 100 Place these 10 values ​​(in order) on the diagonal of a square matrix that we will call A. Generate a 10x10 matrix C with random values. In the problem, each ...
1 vote
40 views

### Miller-Rabin primality test final decision.

I feel like this question is more about math than, programming but it will include some simple code for the Miller-Rabin test (in scheme-lisp). ...
• 11
25 views

### Quadratic programming with diagonal matrix

I am working on an optimization engineering problem that can be transformed into a quadratic programming solution problem, which can be formulated as enter image description here Where H is a ...
24 views

### How can we identify the new geometrical shapes created from one another.

I want to find out the shapes that are created when a line passes over. For eg:- if a line passes through a rectangle, two similar or different shapes are created.as the number of lines passing over ...
32 views

### How do I represent hexagons (or any polygon really) so that they are equal independent of rotation?

I am working on a private coding project. My program works with hexagons, which edges have certain features. I currently represent these hexagons using arrays with one entry for each edge. There is a ...
147 views

### Can you please help me whether $N-R$ method or other methods converges?

Consider the system of equations \begin{align} &f(x,y)=x+\frac{y^4}{2}+\frac{x^{32}}{4}+\frac{y^{128}}{8}=0 \\ &g(x,y)=y+\frac{x^8}{2}+\frac{y^{32}}{4}+\frac{x^{256}}{8}=0. \end{align} I want ...
• 9,500
58 views

### Probability of getting 2 Consecutive heads in N throws.

We have to Find a Probability of Getting ${2}$ consecutive Heads in ${N}$ throws Given that $N^{th}$ throw will always be Head. For Example:- N = 3, Possible Conditions = HHH, HTH, THH, TTH = 4 ...
1 vote
51 views

### Is it coherent to treat the C programming language as a formal system?

In mathematical logic, a formal system is a structure which includes, amongst other things, a set of axioms, and which is able to determine the truth or falsehood of statements with respect to those ...
• 145
1 vote
46 views

### Proof (More rigorous) for LeetCode: 11. Container With Most Water problem

I came across this problem yesterday and I was struggling understanding the solution. I'll give my version for the proof of correctness of the algorithm (leetcode lists such a problem as a greedy ...
• 5,006
39 views

### Inductive proof for recursive function

Let $\Sigma$ denote an alphabet and $[ \Sigma ]$ set of lists over the alphabet. I've encountered the following function: $f([])=[]$ $f([x])=[x]$, for $x \in \Sigma$ $f(x:L)=f(L)$, for $x \in \Sigma$ ...
• 11
45 views

### Are there infinitely many numbers $X$ so that both $X+1$ and $\frac{X}{2}+1$ are squares?

My grandad gave me a challenge and, like any non-cheating child, I wrote a program to solve it for me It goes like this: $48$ is a peculiar number, because $48+1$ is square, and $\frac{48}{2}+1$ is ...
15 views

### algorithm problem in getting rid of double counting in nearest neighbor list?

I have a list of nearest neighbors; as an example you can look at the following list: tes1=[1 2; 1 3; 1 5; 2 1; 2 3; 2 6]; In this list atom 1 is nearest neighbor ...
31 views

I have been trying to compute the pfaffian of skew-symmetric matrices. Currently, I am using the armadillo library. But the time complexity is exponential. Can you please suggest some efficient ways? ...
1 vote
33 views

### Is there any correspondence between higher and lower order logics vs higher and lower level programming languages?

I work as a programmer, and, outside of work, I sometimes dip into mathematical logic. My intuition alerted me to some possible connections between my job and my hobby, and I thought this might be a ...
• 145
17 views

### finding the first intersection between a 3d line and set of points

I need to solve this I have a line in space, starts with (X_0,Y_0,Z_0) and defined by angles θ,φ as: x=r sin⁡θ cos⁡φ; y=r sin⁡θ sin⁡φ ; z=r cos⁡φ we also have a huge set of points distributed in ...
18 views

• 195
10 views

### How to remove "root(f(z), z, n)" from solve solution in MatLab

Wondering if it is possible to remove the expression "root(f(z), z, n)" from the solution presented by the solve function. In this case, my code is listed below and the outputs of "...
56 views

### Is there some method to do mathematical deduction on computer instead of with pen?

Sorry if this question is not too fit into the website. I want to know if there're some methods that we can actually do mathematical deduction with formulae just on the computer instead of with pen ...
• 173
98 views

### How to draw a planar-embedded graph in a visually pleasing way

I have a graph with two types of vertices: "boundary" vertices have degree 1, and "interior" vertices have degree 4. I've computed a planar embedding of the graph, i.e. around each ...
• 9,037
20 views

### Is there any bias choosing a random number $1\ldots n$ in C as $1+(\mbox{rand}()\%n)$

I need random numbers $1\ldots n$ in a program written in C. The library rand() function returns numbers in the range $0\ldots\mbox{RAND_MAX}$, where $\mbox{RAND_MAX}$ is typically $\sim2^{31}-1$. So ...
• 136
15 views

### Resources with examples for Bayesian Data Analysis in R

I'm taking a course on Bayesian Data Analysis, and currently I need to do a project that requires the use of $R$ as a programming language. The goal of the project is to use basic Bayesian Inference ...
• 334
2k views

### What's special about the number $1.000000015047466$E+$30$?

I'm a programmer by trade by I've run into a weirdly special number and need some help deciphering its significance. I was writing some machine learning code that compiles into GPU kernel code and the ...
• 233
72 views

### Determining if a line passes through a rectangular prism

I am working on a programming project and I am trying to figure out when a line passes through a rectangular prism. I have learned about parametrization and how to figure out if a line passes through ...
• 79
5 views

### Getting conditions about positivity of the solutions. Could you suggest me a program that could help with this?

I have an algebraic second degree equation, with five parameters in each coefficiente. This is troublesome to work. I'd like to get parameter's conditions about positivity of the solutions. Could you ...
• 1,205
16 views

### Prove a tight bound on the runtime of the following algoirthm [closed]

function myfunc(n): // n is a positive integer greater than or equal to 2 i = 2; while (i <= n): i = i * i return; We know that if we ...
9 views

### I am trying to plot a density histogram in r

I am trying to write a density histogram in r. Here is my r code below: library(BSDA) alc1 = c(12.3, 12.7, 13.6, 12.7, 12.9, 12.6, 12.6, 13.1, 12.6, 13.1, 12.7, 12.5, 13.2, 12.8, 12.4, 12.6, 12.4, 12....
72 views

### Iterating (programmatically) over "all" integer polynomials (how to order them and when to stop to be sure we checked all what we wanted?)

I have some annoyingly stubborn problems that are basically of the form "are all integer polynomials of some kind a sum of a few products of polynomials of some other kind?". For instance I ...
41 views

### Recursive formula does not work as intended

For my cs class Ive been given the following task. I have n different beers, and the i'th beer has a price of p[i]. the prices are: p1 = 2, p[2] = 3, p[3] = 2, p[4] = 1, p[5] = 4. I also have c coins, ...
31 views

### Calculate the redundancy of a message

To calculate the entropy of a message, I have to calculate the entropy of the language then multiply the result by the length of this message, but then how can I calculate the redundancy of this ...
22 views

### Recursive formula problem in Dynamic programming [duplicate]

For my cs class Ive been given the following task. I have n different beers, and the i'th beer has a price of p[i]. the prices are: p1 = 2, p[2] = 3, p[3] = 2, p[4] = 1, p[5] = 4. I also have c coins, ...
60 views

### How to compute reflection vectors co-planar to a given bivector for rotor creation in G(3)

I've been trying to figure out how to write a C program that generates vectors of reflection $v$ and $w$ separated by an angle of $\frac{\theta}{2}$ that combine to form a rotor $R$ given an arbitrary ...
• 117
77 views

### How to calculate the new $x$, and $y$ coordinates of a scaled rotated rectangle?

I want to scale a rotated rectangle around it's centre point and find the new $x$ and $y$ coordinates - In this diagram given I know $(x, y), \theta , w , h , nw$, and $nh$ - does anyone ideas how I ...
72 views

### Programming books for mathematicians

Are there any good intro to programming books for people with a strong backround in mathematics, but little experience in coding? In particular, are there any books that introduce the different ...
• 319
30 views

### Extended gcd pseudocode

I need to implement extended Euclidian algortihm for polynomials to get coefficients of Bézout's identity. Problem is I'm struggling with correct implementation of such function. I've found some code ...
18 views

### diagramming a poset of rectangles

Would it be feasible to program a computer to search for solutions to the following diagramming problem, say for up to $100$ rectangles? Given a strict partial order on $n$ rectangles of fixed areas ...
• 1,305
1 vote
53 views

### Why are giotto-tda and cripser giving different persistent diagrams?

When I find the persistence diagrams using cubical homology and using the natural grayscale filtration of the image, I get two different answers depending on the package I use. By inspection, it seems ...
• 990
12 views

### multiplying two different numbers by two special numbers to get into max limit

i need some algorithm and all i can think of is manually try all possible multiplications and compare each to result. problem: -all numbers are decimal -we have number Y and number X which are known -...
32 views

### 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 ...
• 11
1 vote
68 views

### How to proof that a equation without operators has only one solution?

I need help with a logical thing. Suppose I have an equation with multiple numbers (which are all single digits and 1-9). For example: $4 * 4 - 3 = 13.$ How can I proof, that this equation has only ...
• 21
47 views

### Projectile motion for negative height and angle

I'm trying to implement a turret in a game that compensate for bullet drop, I'm using the equations 1) and 2) from the next image to obtain the angle of the turret and time of flight. But it doesn't ...
• 1
30 views

### How do you express $\nu_2(n)$ as a SymPy expression so that SymPy's simplification algorithm supports it?

$\nu_2(n)$ is the completely additive arithmetic function that is the maximum power $k$ such that $2^k \mid n$. How do I use SymPy to represent this function. I can calculate it by hand doing: ...
• 19.5k
1 vote
28 views

### What is the name of this family of functions or curves?

Some time ago I was involved at work in making some mechanism to limit and control of an actuator based on a sensor reading $x$, a lower bound $a$, an upper bound $b$, and an "aggressiveness&...
44 views

### Calculating Perpendicular Speed

This question is relating to a 2d game I am programming for. There are 2 discs at positions (coordinates x & y): Disc1 is moving (at xspeed & yspeed) Disc2 is stationary Knowing all the ...
• 1
1 vote
32 views

### How can I calculate an equation with decimal point exponents on a primitive calculator?

By primitive calculator, I really mean a type of scripting that can only calculated by adding, subtracting, multiplying, and dividing numbers that can be either negative or positive but not a decimal. ...
59 views

### How to rotate into a vector direction

I have a vector $$start-end = u \in \mathbb{R^{3}}$$ and a Rotationmatrix which takes three angles as arguments and rotates like: $$M_{rot} = M_{Z} M_{Y}M_{X}$$ How can i calculate the angles, ...
20 views

### Align object to vector

I went through other topics but did not find an answer to my question: I have: two vectors start and end which act as strating/...
25 views

### Depth of a Function.

I'm working on a symbolic integration problem formulation. I'm kinda stuck with the concept of "depth" of function (integrand). It's a Heuristic algorithm to do integration. The depth of a ...
23 views

### Find scale factors to maximize images size

I have two images with dimensions $w_1 \times h_1$ and $w_2 \times h_2$ respectively. I want to display them in a screen of size $w_{screen} \times h_{screen}$. My goal is to resize those images with ...
16 views

### Closest Number to two other numbers while maintaing ratio

I wanted to essentially compute the scaling factor of 2 numbers, based on two other numbers (I am unable to describe it well). Eg: Lets say I have an image of size 200x300 (aspect is 2:3) and I need ...