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

Filter by
Sorted by
Tagged with
-3 votes
0 answers
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 ...
user avatar
1 vote
1 answer
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). ...
user avatar
  • 11
0 votes
0 answers
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 ...
user avatar
-1 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 1
3 votes
2 answers
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 ...
user avatar
  • 9,500
0 votes
1 answer
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 ...
user avatar
  • 5
1 vote
0 answers
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
  • 5,006
0 votes
1 answer
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$ ...
user avatar
  • 11
2 votes
1 answer
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
0 votes
1 answer
31 views

Pfaffian skew-symmetric using armadillo

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? ...
user avatar
1 vote
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
0 votes
0 answers
18 views

Pairwise Matchup Probabilities from Tournament Placement Probabilities

Suppose we have a symmetric $k$ round single elimination tournament. Let $T$ denote the set of teams. Suppose I have a model that spits out the following data: for every team $t \in T$ and $r \in \{1, ...
user avatar
  • 813
1 vote
1 answer
58 views

Detect intervals in which period-doubling biffurcations occur

Let $F_\mu (x) = \mu x (1-x)$ be the logistic map. Our goal is to find -numerically- intervals $[\mu_i, \mu_{i+1}]$ in which a period-doubling biffurcation occurs, for some unique $\mu \in [\mu_i, \...
user avatar
  • 195
0 votes
0 answers
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 "...
user avatar
3 votes
1 answer
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 ...
user avatar
  • 173
5 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 136
0 votes
0 answers
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 ...
user avatar
  • 334
13 votes
1 answer
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 ...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 79
0 votes
0 answers
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 ...
user avatar
  • 1,205
-1 votes
1 answer
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 ...
user avatar
0 votes
0 answers
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....
user avatar
2 votes
1 answer
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 ...
user avatar
0 votes
1 answer
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, ...
user avatar
0 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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, ...
user avatar
0 votes
1 answer
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 ...
user avatar
  • 117
2 votes
4 answers
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 ...
user avatar
2 votes
0 answers
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 ...
user avatar
  • 319
0 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
0 votes
0 answers
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 -...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 11
1 vote
0 answers
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 ...
user avatar
  • 21
0 votes
0 answers
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 ...
user avatar
  • 1
0 votes
1 answer
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: ...
user avatar
1 vote
0 answers
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&...
user avatar
0 votes
2 answers
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 ...
user avatar
  • 1
1 vote
0 answers
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. ...
user avatar
0 votes
1 answer
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, ...
user avatar
0 votes
0 answers
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/...
user avatar
0 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar

1
2 3 4 5
12